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!
If keep your code the same as you have in your question and you change your method signature of
onSuccess(String clientToken)
toonSuccess(int responseCode, Header[] responseHeaders, String responseBody)
the response body will be the StringonSuccess
is called with. This will be your client token from your server.