錯誤集錦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();
}
}
});
}











發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章