java无法重写JsonHttpResponseHandler中的onSuccess()方法
我正在http://www.raywenderlich.com/78578/安卓-tutorial-for-beginners-part-3学习restful服务
当遇到
AsyncHttpClient client = new AsyncHttpClient();
client.get(QUERY_URL + urlString,
new JsonHttpResponseHandler() {
@Override
public void onSuccess(JSONObject jsonObject) {
// Display a "Toast" message
// to announce your success
Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();
// 8. For now, just log results
Log.d("omg 安卓", jsonObject.toString());
}
@Override
public void onFailure(int statusCode, Throwable throwable, JSONObject error) {
// Display a "Toast" message
// to announce the failure
Toast.makeText(getApplicationContext(), "Error: " + statusCode + " " + throwable.getMessage(), Toast.LENGTH_LONG).show();
// Log error message
// to help solve any problems
Log.e("omg 安卓", statusCode + " " + throwable.getMessage());
}
});
我的gradle同步任务成功了。但我不明白为什么onSuccess方法被启发为(方法不重写超类)
甚至我也将onSuccess()参数更改为
public void onSuccess(int statusCode, org.apache.http.Header[] headers, JSONObject jsonObject)
我还遵循了以下链接中提供的所有解决方案
method does not override or implement a method from a supertype - for Override
甚至我也尝试过使用接口。我使用的是异步http 1.4.9 因此,我将gradle脚本更改为
dependencies {
...
// there may or may not be a support library above these
compile 'com.loopj.安卓:安卓-async-http:1.4.9'
compile 'com.squareup.picasso:picasso:2.5.2'
}
我已经尝试了stackoverflow和github中所有可用的解决方案。但我仍然无法清除该错误,它向我显示onSuccess()和onFailure()方法没有覆盖超类
# 1 楼答案
在
onSuccess
函数调用的开始处这将修复您的错误。重写方法时,通常也会调用原始方法(超类的方法)
同样适用于
onFailure
您可以检查此link以查看每个回调函数的参数
正如@hegazy所提到的,您为函数使用了错误的标题,您遵循的教程很可能已经过时。检查链接中所有可能具有正确标题的函数。在
super
调用中,可以传递相同的变量# 2 楼答案
只要使用正确的标题
尝试:
# 3 楼答案
检查你的进口
试试这个
您使用了错误的头并覆盖了不存在的方法。我想这些可能是旧版本中提供的