Android must implement inherited abstract method

I have uploaded a project with this feature where it works well, but when I matched this feature in my project I get errors:

The type new AsyncHttpResponseHandler(){}

must implement an inherited abstract methodAsyncHttpResponseHandler.onSuccess(int, Header[], byte[])

A onSuccess(String)

type method new AsyncHttpResponseHandler(){}

must override or implement a supertype method

A onFailure(int, Throwable, String)

type method new AsyncHttpResponseHandler(){}

must override or implement a supertype method

I tried all the tips from this question but nothing seems to work. Any possible solution?

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

      

+3


source to share


1 answer


You cannot create a new signature to override methods, according to your error and API

your methods MUST have the same signature than the superclass / interface

Check JLS (ยง8.4.2)

This implies that it is a compile-time error if [...] a method with a signature equivalent to overriding [...] has a different return type or an incompatible cast.

In your case, these signatures 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) {

      

Renewal .... declare your methods as above in the AsyncHttpResponseHandler

API
and add them to meet your needs
.

+3


source







All Articles