2

I am learning restful services in http://www.raywenderlich.com/78578/android-tutorial-for-beginners-part-3

while coming across

 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());
}
        });

My gradle sync task was successful.But I couldn't figure out that why onSuccess method is enlightened as (Method does not override super class)

Even I have changed the onSuccess() parameters to

 public void onSuccess(int statusCode, org.apache.http.Header[] headers, JSONObject jsonObject)

and also I have followed all the solutions provided in the following links

method does not override or implement a method from a supertype - for Override

AndroidAsyncHttp Error

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

Even I have tried using interfaces also.And I am using async http 1.4.9 So I have changed the gradle scripts as

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'
}

I have tried all the solutions available in stackoverflow and github.But still I couldn't clear that error and it is showing me onSuccess() and onFailure() methods doesn't override the superclass

Community
  • 1
  • 1

3 Answers3

7

Check you imports

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

import org.json.JSONObject;

**import cz.msebera.android.httpclient.Header;**

and try this

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);
    }
});

You are using the wrong Header and overriding nonexistent methods. I think may be those were available on an old release.

Ahmed Hegazy
  • 12,395
  • 5
  • 41
  • 64
1

At the start of the onSuccess function call

super.onSuccess();

This will fix your error. When you override a method, it is common to also call the original method (the super class's method).

Same for onFailure

super.onFailure();

You can check this link to see the parameters of each callback function.

As already mentioned by @hegazy you use wrong headers for the functions, the tutorial you followed is most likely outdated. Check the link for all possible functions with correct headers. In the super calls you can pass the same variables.

Niki van Stein
  • 10,564
  • 3
  • 29
  • 62
0

just use the right header

Try:

@Override
public void  onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject response) {
   // called when response HTTP status is "200 OK"
}

@Override
public void onFailure(int statusCode,cz.msebera.android.httpclient.Header[] headers, Throwable e, JSONObject response) {

}
RKRK
  • 1,284
  • 5
  • 14
  • 18