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

Java-Android必须实现继承的抽象方法,第1张

概述我已经下载了具有此功能的项目,并且效果良好,但是当我将此功能复制到项目中时,出现错误:ThetypenewAsyncHttpResponseHandler(){}mustimplementtheinheritedabstractmethodAsyncHttpResponseHandler.onSuccess(int,Header[],byte[])ThemethodonSuccess(String)of

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

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,您的方法必须与超级类/接口具有相同的签名:

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必须实现继承抽象方法全部内容,希望文章能够帮你解决Java-Android必须实现继承的抽象方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1080020.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存