简体   繁体   English

JsonHttpResponseHandler - 方法不会覆盖其超类中的方法

[英]JsonHttpResponseHandler - method does not override method from its superclass

I have been struggling with this code for some time now. 我一直在努力使用这段代码。 Why am I getting the follow error? 为什么我收到以下错误? method does not override method from its superclass Here is the code: 方法不会覆盖其超类的方法这是代码:

public void CanSendPassword() {
    asyncHttpClientPassword = new AsyncHttpClient();
    requestParamsPassword = new RequestParams();

    requestParamsPassword.put("email", mEmail);
    asyncHttpClientPassword.post(BASE_URL, requestParamsPassword, new JsonHttpResponseHandler()
    {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            jsonResponse = response.toString();
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            super.onFailure(statusCode, headers, throwable, errorResponse);
            jsonResponse = "failed";
        }
    }
    );
}

@override both are showing the same error and onSuccess and onFailure are greyed out too? @override都显示相同的错误,onSuccess和onFailure也显示为灰色?

Here is my code 这是我的代码

TwitterRestClient TwitterRestClient

import android.content.Context;
import com.loopj.android.http.*;
import cz.msebera.android.httpclient.entity.StringEntity;

public class TwitterRestClient {
    private static final String BASE_URL = "https://www.example.com/api/";

    private static AsyncHttpClient client = new AsyncHttpClient();

    public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    client.get(getAbsoluteUrl(url), params, responseHandler);
    }

    public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    client.post(getAbsoluteUrl(url), params, responseHandler);
    }

    public static void post(Context ctx, String url, StringEntity entity, java.lang.String contentType, AsyncHttpResponseHandler responseHandler ){
    client.post(ctx,getAbsoluteUrl(url),entity,contentType,responseHandler);
    }

    private static String getAbsoluteUrl(String relativeUrl) {
        return BASE_URL + relativeUrl;
    }
}

This the method in my LoginAcitivity 这是我的LoginAcitivity中的方法

public void testPost(StringEntity entity) throws JSONException {
    TwitterRestClient.post(getApplicationContext(),"api-auth/", entity,"application/json", new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, org.json.JSONArray response) {
            // If the response is JSONObject instead of expected JSONArray
            GlobalFunctions.ShowToast(getApplicationContext(),"test");
        }

        @Override
        public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, java.lang.Throwable throwable, org.json.JSONArray errorResponse){
            GlobalFunctions.ShowToast(getApplicationContext(),"test1123");
        }

        @Override
        public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, java.lang.Throwable throwable, org.json.JSONObject errorResponse){
            GlobalFunctions.ShowToast(getApplicationContext(),errorResponse.toString());
        }

        @Override
        public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, java.lang.String responseString, java.lang.Throwable throwable){
            GlobalFunctions.ShowToast(getApplicationContext(),responseString);
        }
    });
}

This is what i call when user clicks the button 这是我在用户点击按钮时调用的内容

public void signIn(View v){
    try {

        String url = "/api-auth";

        JSONObject jsonParams = new JSONObject();

        jsonParams.put("username", "binsoi@gmail.com");
        jsonParams.put("password", "cornedbeef");

        StringEntity entity = new StringEntity(jsonParams.toString());
        client.post(context, url, entity, "application/json",
                responseHandler);

        testPost(entity);


    }  catch (Exception err)
    {
        GlobalFunctions.ShowToast(this, err.toString());
    }
}

Hope this will help you, tell me if it this doesn't work because i edited this before posting. 希望这会对你有所帮助,告诉我这是不行的,因为我在发布之前编辑了这个。

Here is a solution that I have working but it does not solve my exact issue. 这是我工作的解决方案,但它没有解决我的确切问题。 I post this as I can not understand why this code works but my code does not. 我发布这个,因为我无法理解为什么这段代码有效但我的代码没有。

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

EditText etSearchTerms;
Button btnSearch;
TextView tvSearchResults;
MyLoopjTask myLoopjTask;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    etSearchTerms = (EditText) findViewById(R.id.etSearchTerms);
    btnSearch = (Button) findViewById(R.id.btnSearch);
    tvSearchResults = (TextView) findViewById(R.id.tvSearchResults);

    btnSearch.setOnClickListener(this);

    myLoopjTask = new MyLoopjTask();
}

@Override
public void onClick(View v) {
    String searchTerm = etSearchTerms.getText().toString();
    etSearchTerms.setText("");
    // make loopj http call
    myLoopjTask.executeLoopjCall(searchTerm);
}
}

And here is the other class: 这是另一个类:

public class MyLoopjTask {


AsyncHttpClient asyncHttpClient;
RequestParams requestParams;

String BASE_URL = "https://team.mycompany.com/teambeta/LoginApp/Recovery/";
String jsonResponse;

public MyLoopjTask() {
    asyncHttpClient = new AsyncHttpClient();
    requestParams = new RequestParams();
}

public void executeLoopjCall(final String queryTerm) {

    requestParams.put("email", queryTerm);
    asyncHttpClient.post(BASE_URL, requestParams, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            jsonResponse = response.toString();
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            super.onFailure(statusCode, headers, throwable, errorResponse);
            jsonResponse = "failed";
        }
    });
}
}

So why does this code work but not in my oringinal question? 那么为什么这段代码可以工作而不是我的oringinal问题呢?

Finally solved my issue. 终于解决了我的问题。 It was not the code as I was doing everything correctly. 这不是代码,因为我正在做正确的事情。 I just had the old jar file still in the app/libs folder. 我只是将旧的jar文件保存在app / libs文件夹中。

And here is the error I was seeing. 这是我看到的错误。 Everything was working but Override and the super.onSuccess were red underlined. 一切正常,但是Override和super.onSuccess都是红色下划线。

在此输入图像描述

在此输入图像描述

Remove the android-async-1.4.3.jar file and the red lines disappeared. 删除android-async-1.4.3.jar文件,红线消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM