Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonHttpResponseHandler - method does not override method from its superclass

I have been struggling with this code for some time now. Why am I getting the follow error? method does not override method from its superclass Here is the code:

public void CanSendPassword() {
    asyncHttpClientPassword = new AsyncHttpClient();
    requestParamsPassword = new RequestParams();

    requestParamsPassword.put("email", mEmail);
    asyncHttpClientPassword.post(BASE_URL, requestParamsPassword, new JsonHttpResponseHandler()
    {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            jsonResponse = response.toString();
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            super.onFailure(statusCode, headers, throwable, errorResponse);
            jsonResponse = "failed";
        }
    }
    );
}

@override both are showing the same error and onSuccess and onFailure are greyed out too?

like image 704
timv Avatar asked May 28 '26 16:05

timv


1 Answers

Here is my code

TwitterRestClient

import android.content.Context;
import com.loopj.android.http.*;
import cz.msebera.android.httpclient.entity.StringEntity;

public class TwitterRestClient {
    private static final String BASE_URL = "https://www.example.com/api/";

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

    public static void post(Context ctx, String url, StringEntity entity, java.lang.String contentType, AsyncHttpResponseHandler responseHandler ){
    client.post(ctx,getAbsoluteUrl(url),entity,contentType,responseHandler);
    }

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

This the method in my LoginAcitivity

public void testPost(StringEntity entity) throws JSONException {
    TwitterRestClient.post(getApplicationContext(),"api-auth/", entity,"application/json", new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, org.json.JSONArray response) {
            // If the response is JSONObject instead of expected JSONArray
            GlobalFunctions.ShowToast(getApplicationContext(),"test");
        }

        @Override
        public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, java.lang.Throwable throwable, org.json.JSONArray errorResponse){
            GlobalFunctions.ShowToast(getApplicationContext(),"test1123");
        }

        @Override
        public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, java.lang.Throwable throwable, org.json.JSONObject errorResponse){
            GlobalFunctions.ShowToast(getApplicationContext(),errorResponse.toString());
        }

        @Override
        public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, java.lang.String responseString, java.lang.Throwable throwable){
            GlobalFunctions.ShowToast(getApplicationContext(),responseString);
        }
    });
}

This is what i call when user clicks the button

public void signIn(View v){
    try {

        String url = "/api-auth";

        JSONObject jsonParams = new JSONObject();

        jsonParams.put("username", "[email protected]");
        jsonParams.put("password", "cornedbeef");

        StringEntity entity = new StringEntity(jsonParams.toString());
        client.post(context, url, entity, "application/json",
                responseHandler);

        testPost(entity);


    }  catch (Exception err)
    {
        GlobalFunctions.ShowToast(this, err.toString());
    }
}

Hope this will help you, tell me if it this doesn't work because i edited this before posting.

like image 187
Binsoi Avatar answered May 30 '26 05:05

Binsoi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!