Chris Chris - 2 years ago 153
Android Question

onSuccess - Asynchronous Http Client

I'm using the Android Asynchronous Http Client. My code looks like this and is working fine."RegisterUser", params, new AsyncHttpResponseHandler() {
public void onSuccess(String answer) {
// initialize variables
JSONObject json = new JSONObject();
String message = null;

try {
// turn string into JSONObject
json = new JSONObject(answer);
message = json.getString("message");
} catch (JSONException e) {
Log.e("ERROR", e.getMessage());

// registration was successful
if (message.equals("success")) {
// forward to login page
} else {
// error

I implemented a static HTTP Client. My server returns this JSON data
. I do not want to treat it as a String and cast it back to JSON. But when I change it to
public void onSuccess(JSONObject answer)
eclipse tells me

The method onSuccess(JSONObject) of type new
AsyncHttpResponseHandler(){} must override or implement a supertype

Answer Source

The correct method signature would be this public void onSuccess(int statusCode, Header[] headers, JSONObject response) or any of the other available methods in the JsonHttpResponseHandler class

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download