无法覆盖JsonHttpResponseHandler中的onSuccess()方法

Sow*_*ran 2 java rest android asynchttpclient

我正在http://www.raywenderlich.com/78578/android-tutorial-for-beginners-part-3学习宁静的服务

遇到的时候

 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 android", 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 android", statusCode + " " + throwable.getMessage());
}
        });
Run Code Online (Sandbox Code Playgroud)

我的gradle sync任务成功.但我无法弄清楚为什么onSuccess方法被启发为(Method不会覆盖超类)

即使我已将onSuccess()参数更改为

 public void onSuccess(int statusCode, org.apache.http.Header[] headers, JSONObject jsonObject)
Run Code Online (Sandbox Code Playgroud)

我也遵循以下链接中提供的所有解决方案

方法不会覆盖或实现超类型的方法 - 对于覆盖

AndroidAsyncHttp错误

http://answered.site/-heres-my-mainactivityjava-the-part-of-the-code-it-occurs-in-the-querybooks/2950406/

即使我也尝试过使用接口.我正在使用async http 1.4.9所以我已经将gradle脚本更改为

dependencies {

    ...

    // there may or may not be a support library above these
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.squareup.picasso:picasso:2.5.2'
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了stackoverflow和github中可用的所有解决方案.但我仍然无法清除该错误,它显示我onSuccess()和onFailure()方法不会覆盖超类

Ahm*_*azy 6

检查你的进口

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;

import org.json.JSONObject;

**import cz.msebera.android.httpclient.Header;**
Run Code Online (Sandbox Code Playgroud)

试试这个

client.get("sdsd", new JsonHttpResponseHandler() {
    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        super.onSuccess(statusCode, headers, response);

    }

    @Override
    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
        super.onFailure(statusCode, headers, throwable, errorResponse);
    }
});
Run Code Online (Sandbox Code Playgroud)

您正在使用错误的标头并覆盖不存在的方法.我想可能是那些旧的版本可用.