Java-Android必须实现继承的抽象方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java-Android必须实现继承的抽象方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3198字,纯文字阅读大概需要5分钟。
内容图文
![Java-Android必须实现继承的抽象方法](/upload/InfoBanner/zyjiaocheng/662/5a4b616ce3ac48589d33436a5fc35154.jpg)
我已经下载了具有此功能的项目,并且效果良好,但是当我将此功能复制到项目中时,出现错误:
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
我尝试了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,您的方法必须与超级类/接口具有相同的签名:
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必须实现继承的抽象方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。