3

I am using android-async-http, and override all the onSuccess and onFailure method, but I got the error: onSuccess(int, Header[], JSONObject) was not overriden, but callback was received.

cz.msebera.android.httpclient.client.HttpResponseException: Not Found

I just wonder I truely override this method. Also I got the log:onSuccess JSONObject:{"error":null,"success":false}

  public static void querySecurityCode(String username) {
        RequestParams params = new RequestParams();
        params.put("username", username);
        VStarRestClient.getClient().setEnableRedirects(true);
        VStarRestClient.post(GET_SECURITY_CODE_URL, params, new JsonHttpResponseHandler(){
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                Log.i("ws", "---->>onSuccess JSONObject:" + response);
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                super.onSuccess(statusCode, headers, response);
                Log.i("ws", "---->>onSuccess JSONArray");
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                super.onSuccess(statusCode, headers, responseString);
                Log.i("ws", "---->>onSuccess responseString");
            }


            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                Log.i("ws", "---->>onFailure:" + throwable.toString());
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);
                Log.i("ws", "---->>onFailure" + throwable.toString());
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);
                Log.i("ws", "---->>onFailure" + throwable.toString());
            }


        } );
    }
Shuai Wang
  • 335
  • 1
  • 8
  • 20

4 Answers4

7

You shouldn't call super.onFailure and super.onSuccess, that warning comes from super methods when you're not overriding them.

Hsingchien Cheng
  • 594
  • 6
  • 13
1

I faced same issue. My Rest API return array of JSONObjects ie JSONArray. but my code try to collect in JSONObjects.

Soluion: below code Working fine for me. JsonHttpResponseHandler's Override method

public void onSuccess(int statusCode, Header[] headers, JSONArray response) { }

instead of override with below method that cause an error: public void onSuccess(int statusCode, Header[] headers, JSONObject response) { }

Rajeev Rathor
  • 1,830
  • 25
  • 20
0

Try this lines

public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

System.out.println("Received event with data: " + response);
}
0

JsonHttpResponseHandler have 2 OnFailure overriding methods. Try another one

Arun Jose
  • 76
  • 6