错误集锦20180522

Error:Could not resolve all files for configuration ':app:huaweiDebugAnnotationProcessorClasspath'.
> Could not resolve com.jakewharton:butterknife-compiler:8.8.1.
  Required by:
      project :app
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   > No cached version of com.jakewharton:butterknife-compiler:8.8.1 available for offline mode.
   
   解决方案:(误打误撞解决的)
   1、新建一个项目,只在app的build.gradle文件里面加入:
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
然后同步,然后调用:
@BindView(R.id.butterKnifeBtn)
    Button butterKnifeBtn;
ButterKnife.bind(this);发现没有问题
2、在出问题的项目中将以下两句注释掉,同步运行,然后再取消注释,再同步运行,就没有以上问题了
   compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'




 Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
 Conflict with dependency 'com.android.support:support-annotations' in project ':app'.
 Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
    
解决方案:
注释掉以下两句:
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementationandroidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
换成以下:
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
或者干脆只注释掉不加下面的也行,反正没怎么用到



声明List<JSONObject> jsonObjects = new ArrayList<>();然后用jsonObjects.add(key,value)添加元素,只能按顺序添加,
比如添加完了jsonObjects.add(0,value)才能添加jsonObjects.add(1,value),直接添加jsonObjects.add(10,value)是添加不进去的,
虽然元素添加不进去,但是jsonObjects的size在增加,并且jsonObjects的size在没有添加元素的时候不是0,才发现,好神奇。
改成Map<Integer,JSONObject> jsonObjects就可以想怎么添加怎么添加,size也是从0开始的,
用Map不用HashMap是因为HaspMap会做自动装箱和自动拆箱(Integer和int互相转换)消耗系统资源。






XUtils HttpUtils 优化线程 防止无限访问网络
解决方案:
httpUtils.send()返回的是一个异步线程HttpHandler<String> handler,每次请求之前判断一下handler,若之前的请求还没有完成,直接handler.cancel()取消掉,然后才开始本次的请求,
这样就可以只保留最后一次请求,防止无限访问网络,也可以防止因为请求太多,最后一次的请求结果返回很慢,导致数据刷新不及时,用户体验很差。
上代码:
private void getData(final GridView gv, String date, final int position) {
//如果之前的线程没有完成
if(handler!=null && handler.getState()!= HttpHandler.State.FAILURE && handler.getState()!= HttpHandler.State.SUCCESS && handler.getState()!= HttpHandler.State.CANCELLED
&& Math.abs(lastPoisition - position) > 1){
//关闭handler后 onStart()和onLoading()还是会执行
handler.cancel();
}
HttpUtils httpUtils = new HttpUtils();
RequestParams params = new RequestParams();
params.addBodyParameter("cmd", "CollectionPlan");
params.addBodyParameter("userId", app.persionData.getUser_id());
handler = httpUtils.send(HttpMethod.POST, URLS.borrowCollection, params, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
ToastErrorUtils.Show(CashSchemesActivity.this, arg0, arg1);
}


@Override
public void onCancelled() {
super.onCancelled();
L.i("wanlijun","onCancelled");
}


@Override
public void onLoading(long total, long current, boolean isUploading) {
super.onLoading(total, current, isUploading);
L.i("wanlijun","onLoading");
L.i("wanlijun","lastPoisition="+lastPoisition);
L.i("wanlijun","position="+position);
}


@Override
public void onSuccess(ResponseInfo<String> arg0) {
try {
JSONObject jsonObject = new JSONObject(arg0.result);
L.i("wanlijun","getData:"+jsonObject.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}











猜你喜欢

转载自blog.csdn.net/u010015933/article/details/80499433