问题
I'm trying to implement the LoopJ AndroidAsyncHttp for a Braintree project. I downloaded the .jar file and added it as a library.
I now have the following code:
public class PayCharge extends Activity {
AsyncHttpClient client = new AsyncHttpClient();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.paycharge);
client.get("https://xxx.herokuapp.com/generateToken.php", new TextHttpResponseHandler() {
@Override
public void onStart() {
// Initiated the request
}
@Override
public void onSuccess(String clientToken) {
// Successfully got a response
}
@Override
public void onFailure(String responseBody, Throwable e) {
// Response failed :(
}
@Override
public void onFinish() {
// Completed the request (either success or failure)
}
});
}
}
However, the TextHttpResponseHandler() part is underlined red with the following error: class 'Anonymous class derived from TextHttpResponseHandler()' must either be declared abstract or implement abstract method onSuccess(int, Header[], string) in TextHttpResponseHandler"
Additionally, both of the onSuccess and onFailure @Override are underlined red claiming that the method does not override from its superclass.
I'm a beginner so not quite sure how to proceed. Thanks!
回答1:
If keep your code the same as you have in your question and you change your method signature of onSuccess(String clientToken)
to onSuccess(int responseCode, Header[] responseHeaders, String responseBody)
the response body will be the String onSuccess
is called with. This will be your client token from your server.
回答2:
...
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
}
...
来源:https://stackoverflow.com/questions/24809387/androidasynchttp-error