【发布时间】:2015-06-10 14:53:50
【问题描述】:
我已经下载了这个功能很好的项目,但是当我把这个功能复制到我的项目中时,我得到了错误:
类型
new AsyncHttpResponseHandler(){}必须实现继承的抽象方法AsyncHttpResponseHandler.onSuccess(int, Header[], byte[])
new AsyncHttpResponseHandler(){}类型的方法onSuccess(String)必须覆盖或实现超类型方法
new AsyncHttpResponseHandler(){}类型的方法onFailure(int, Throwable, String)必须覆盖或实现超类型方法
我尝试了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();
}
}
【问题讨论】:
-
你下载了什么项目?您是否在班级中导入了正确的班级?
-
也许您使用的是 github.com/loopj/android-async-http 的不同版本,
AsyncHttpResponseHandler似乎来自该版本。因此编译器需要不同的方法签名 -
是的,我使用了错误版本的 lib,但我认为问题出在某些版本的 java 编译器上。
标签: java android inheritance