AndroidAsyncHttp Error

核能气质少年 提交于 2020-01-05 08:21:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!