我正在使用来自Loopj的android-async-http库,onFailure没有在我的代码中调用,我已经尝试了所有三种方法..
W / JsonHttpRH:onFailure(int,Header [],String,Throwable)未被覆盖,但收到了回调private void get() {
//Request parameters
RequestParams params = new RequestParams();
params.put("key", API_KEY);
MyRESTClient.get("/posts/", null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
//some code
}
@Override
public void onProgress(long bytesWritten, long totalSize) {
mLoaderProgress.setText((long) 100 * bytesWritten / totalSize + "Loading...");
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
Log.d("Error----> ", ""+statusCode+" ------ "+ errorResponse);
}
});
}
答案 0 :(得分:3)
以下是覆盖的正确方法,
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
super.onFailure(statusCode, headers, responseString, throwable);
Log.d("Failed: ", ""+statusCode);
Log.d("Error : ", "" + throwable);
}
答案 1 :(得分:1)
您需要覆盖正确的方法。一些onFailure是: 1.public void onFailure(int statusCode,Header [] headers,Throwable throwable,JSONObject errorResponse) 2.public void onFailure(int statusCode,Header [] headers,Throwable throwable,JSONArray errorResponse) 3.public void onFailure(int statusCode,Header [] headers,String responseString,Throwable throwable)
选择正确的onFailure以避免错误。
答案 2 :(得分:0)
将此项用于标题
import cz.msebera.android.httpclient.Header;