gpt4 book ai didi

java - Android必须实现继承的抽象方法

转载 作者:可可西里 更新时间:2023-10-31 22:03:44 26 4
gpt4 key购买 nike

我已经下载了具有此功能的项目,它运行良好,但是当我将此功能复制到我的项目中时,出现错误:

The type new AsyncHttpResponseHandler(){} must implement the inherited abstract method AsyncHttpResponseHandler.onSuccess(int, Header[], byte[])

The method onSuccess(String) of type new AsyncHttpResponseHandler(){} must override or implement a supertype method

The method onFailure(int, Throwable, String) of type new AsyncHttpResponseHandler(){} must override or implement a supertype method

我尝试了 this question 中的所有提示但没有任何帮助。任何可能的解决方案?

public void syncSQLiteMySQLDB(){
//Create AsycHttpClient object
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
ArrayList<HashMap<String, String>> userList = controller.getAllUsers();
if(userList.size()!=0){
if(controller.dbSyncCount() != 0){
prgDialog.show();
params.put("usersJSON", controller.composeJSONfromSQLite());
client.post("http://techkeg.tk/sqlitemysqlsync/insertuser.php",params ,new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
System.out.println(response);
prgDialog.hide();
try {
JSONArray arr = new JSONArray(response);
System.out.println(arr.length());
for(int i=0; i<arr.length();i++){
JSONObject obj = (JSONObject)arr.get(i);
System.out.println(obj.get("id"));
System.out.println(obj.get("status"));
controller.updateSyncStatus(obj.get("id").toString(),obj.get("status").toString());
}
Toast.makeText(getApplicationContext(), "DB Sync completed!", Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}

@Override
public void onFailure(int statusCode, Throwable error, String content) {
prgDialog.hide();
if(statusCode == 404){
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
}else if(statusCode == 500){
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", Toast.LENGTH_LONG).show();
}
}
});
}else{
Toast.makeText(getApplicationContext(), "SQLite and Remote MySQL DBs are in Sync!", Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(getApplicationContext(), "No data in SQLite DB, please do enter User name to perform Sync action", Toast.LENGTH_LONG).show();
}
}

最佳答案

根据您的错误和API,您不能为覆盖的方法创建新的签名您的方法必须具有与父类(super class)/接口(interface)相同的签名:

Check JLS (§8.4.2)

It follows that is a compile-time error if [...] a method with a signature that is override-equivalent [...] has a different return type or incompatible throws clause.

在您的情况下,此签名必须是:

public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
// Successfully got a response
}

public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error)
{
// Response failed :(
}

不是:

public void onSuccess(String response) {
public void onFailure(int statusCode, Throwable error, String content) {

正在恢复.... 像上面和AsyncHttpResponseHandler API中描述的那样声明你的方法并添加它们以满足您的需求

关于java - Android必须实现继承的抽象方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30759953/

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