gpt4 book ai didi

java - JsonHttpResponseHandler - 方法不会覆盖其父类(super class)中的方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:56 25 4
gpt4 key购买 nike

一段时间以来,我一直在为这段代码苦苦挣扎。为什么我会收到跟随错误?方法不会覆盖其父类(super class)中的方法这是代码:

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 都显示相同的错误并且 onSuccess 和 onFailure 也变灰了吗?

最佳答案

这是我的代码

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;
}
}

这是我的 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);
}
});
}

这是我在用户点击按钮时调用的内容

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());
}
}

希望这对您有所帮助,如果它不起作用请告诉我,因为我在发布前对其进行了编辑。

关于java - JsonHttpResponseHandler - 方法不会覆盖其父类(super class)中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42640315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com