Android must implement inherited abstract methods
I’ve downloaded a project with this feature and it works fine, but when I copy this feature into my project, I get an error:
The type
new AsyncHttpResponseHandler(){}
must implement the inherited abstract methodAsyncHttpResponseHandler.onSuccess(int, Header[], byte[])
The method
onSuccess(String)
of typenew AsyncHttpResponseHandler(){}
must override or implement a supertype methodThe method
onFailure(int, Throwable, String)
of typenew AsyncHttpResponseHandler(){}
must override or implement a supertype method
I tried All hints in this question, but nothing helps. Any possible solutions?
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();
}
}
Solution
Depending on your error and < a href="http://loopj.com/android-async-http/doc/com/loopj/android/http/AsyncHttpResponseHandler.html" rel="noreferrer noopener nofollow" > API
, you cannot create a new signature for an overridden methodYour method must have the same signature as the parent (super class)/interface:
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.
In your case, this signature must be:
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 :(
}
Not:
public void onSuccess(String response) {
public void onFailure(int statusCode, Throwable error, String content) {
Recovering…. Like above and Declare your methods as described in the AsyncHttpResponseHandler
API and add them to suit your needs.