1
votes

I have a problem with Android Asynchronous Http Client (http://loopj.com/android-async-http/). Until today I used the 1.4.6 version and my code (see below works without problem).

RestClient.get(MyUrl, null, new JsonHttpResponseHandler() {
    @Override
    public void onStart() {
    Toast.makeText(getApplicationContext(), "START", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
        Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT).show();
    }
});

Where RestClient is this:

public class RestClient {
    private static final String BASE_URL = "http://www.example.com/action.php?";

    private static AsyncHttpClient client = new AsyncHttpClient();

    public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    client.get(getAbsoluteUrl(url), params, responseHandler);
    }

    public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.post(getAbsoluteUrl(url), params, responseHandler);
    }

    private static String getAbsoluteUrl(String relativeUrl) {
        return BASE_URL + relativeUrl;
    }
}

After upgrade Android Asynchronous Http Client library from 1.4.6 to 1.4.9 (the last) I get the error "method does not override or implement a method from a supertype" on Android Studio about onSuccess and onFailure methods.

Any ideas about whats is change on library? I have read the changelog but I cannot found a solution. Thanks.

1

1 Answers

0
votes

The interface on those methods have changed. You have: public void onSuccess(int statusCode, Header[] headers, JSONObject response)

public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable)

The updated interface is: public void onSuccess(int statusCode, Header[] headers, byte[] response)

public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e)

Looks like it has changed from taking a String as an argument to using a byte array. Probably to avoid making assumptions about the encoding of your strings.