我正在使用 android asynchttp 1.4.3向http://www.opensecrets.org/api/?method=getLegislators&apikey=xxx&output=json&id=ny发出 GET 请求。我设置了多个断点,但没有抛出异常,并且没有调用以下回调:
APIclient.getLegislators(this, enteredState, new JsonHttpResponseHandler() {
@Override
public void onSuccess(JSONArray arr) {
String s= "hello";
}
@Override
public void onSuccess(JSONObject contactsJson) {
ArrayList<Contact> contacts = Contact.fromJSON(contactsJson);
}
/*@Override
public void onFailure(int statusCode, org.apache.http.Header[] headers, byte[] responseBytes, java.lang.Throwable throwable) {
//super.onFailure(statusCode, headers, responseBytes, throwable);
}*/
@Override
public void onFailure(Throwable arg0, JSONArray arg1) {
super.onFailure(arg0, arg1);
Toast.makeText(getApplicationContext(),
"Failed with JSONArray 2nd arg!", Toast.LENGTH_LONG).show();
}
// If it fails it fails here where arg1 is the error message(dev inactive)
@Override
public void onFailure(Throwable arg0, String arg1) {
super.onFailure(arg0, arg1);
Toast.makeText(getApplicationContext(),
"getTrailerUrl failed with String 2nd arg!",
Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Throwable arg0, JSONObject arg1) {
super.onFailure(arg0, arg1);
Toast.makeText(getApplicationContext(),
"Failed with JSONObject 2nd arg!", Toast.LENGTH_LONG).show();
}
});
我试图通过查看http://loopj.com/android-async-http/doc/com/loopj/android/http/JsonHttpResponseHandler.html来了解这一点
基于该 javadoc,我输入了您看到的已注释掉的回调。我将其注释掉是因为编译器无法识别任何此类父 onFailure 签名。然而,官方文档中没有显示我拥有的不会产生编译器错误的 onFailure。
这篇 SO 帖子中的解决方案显然与我在 2012 年发布该帖子后所拥有的 jar 合并:Loopj Android Async Http - onFailure not fire
我错过了什么回调覆盖?我想看看为什么我的 GET 请求没有成功。谢谢