android遇到的一些问题记录

1、Caused by: java.lang.UnsatisfiedLinkError: No implementation found for int com.baidu.platform.comjni.tools.JNITools.initClass
解决方法:
sourceSets{
main{
jniLibs.srcDirs ‘libs’
}
}

2、Caused by: java.lang.IllegalStateException: you have not supplyed the global app context info from SDKInitializer.initialize(Context) function.
解决方法:
把自定义的MainApplication在Androidmenifest.xml中声明

3、百度地图errorcode: -10 uid: -1 appid -1 msg: Current network is not available.
解决方法:
Androidmenifest.xml中增加访问网络的权限

4、权限问题兼容
解决办法:
Androidmenifest.xml中增加compile ‘com.android.support:support-core-utils:25.3.1’

代码如下:

public void checkPermission(){
    if ((ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
            | (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) != PackageManager.PERMISSION_GRANTED
            | (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) != PackageManager.PERMISSION_GRANTED
            | (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) != PackageManager.PERMISSION_GRANTED)){

        ActivityCompat.requestPermissions(MainActivity.this,
                new String[] {android.Manifest.permission.ACCESS_COARSE_LOCATION,
                        android.Manifest.permission.ACCESS_FINE_LOCATION,
                        android.Manifest.permission.ACCESS_FINE_LOCATION,
                        android.Manifest.permission.WRITE_EXTERNAL_STORAGE
                },
                REQUEST_CODE_ASK_PERMISSIONS);
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    Log.i("TeamGroups", "requestCode = " + requestCode);
    Log.i("TeamGroups", permissions.toString());
    doNext(requestCode, grantResults);
}

private void doNext(int requestCode, int[] grantResults) {

    System.out.println("request code = " + requestCode);
    if (requestCode == REQUEST_CODE_ASK_PERMISSIONS) {
        for (int grantResult : grantResults) {
            Log.i("TeamGroups", "" + grantResult);
        }
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(this, "已授权", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "未授权", Toast.LENGTH_SHORT).show();
        }
    }
}

onCreate()里调用:checkPermission()

5、java.lang.IllegalArgumentException: Could not locate ResponseBody converter
解决方法:

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Constants.API_BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())//这句
            .build();

compile ‘com.squareup.retrofit2:converter-gson:2.0.2’

6、@Body parameters cannot be used with form or multi-part encoding
解决方法:
去掉@FormUrlEncoded

7、使用retrofit进行post传递
LoginActvity:

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(ContentURL.HOME_HOST)
        .addConverterFactory(GsonConverterFactory.create())
        .build();

ApiService service = retrofit.create(ApiService.class);

Call<LoginResponseBean> call = service.login(login);
call.enqueue(new Callback<LoginResponseBean>() {
    @Override
    public void onResponse(Call<LoginResponseBean> call, Response<LoginResponseBean> response) {

        if(response.body().getToken() == null){
            Toast.makeText(LoginActivity.this,R.string.any_error,Toast.LENGTH_SHORT).show();
        }else {
            Log.i("TeamGroups", response.body().getToken());
            Log.i("TeamGroups", response.body().getResult());

            PreferenceUtils.setPrefString(LoginActivity.this, "Token", response.body().getToken());
            Intent intent = new Intent(LoginActivity.this,MainActivity.class);
            startActivity(intent);
        }
    }

    @Override
    public void onFailure(Call<LoginResponseBean> call, Throwable t) {
        t.printStackTrace();
    }
});

ApiService:

public interface ApiService {
    @POST(ContentURL.LOGIN_URL)
    Call<LoginResponseBean> login(@Body LoginBean login);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值