[英]Cannot override doInBackground-method (asyncTask)
為什么我不能在課堂上重寫doInBackground方法?
public class AttemptLogin extends AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected JSONObject doInBackground(String... args) {
String email = args[2];
String password = args[1];
String name= args[0];
ArrayList params = new ArrayList();
params.add(new BasicNameValuePair("username", name));
params.add(new BasicNameValuePair("password", password));
if(email.length()>0)
params.add(new BasicNameValuePair("email",email));
JSONObject json = jsonParser.makeHttpRequest(URL, "POST", params);
return json;
}
protected void onPostExecute(JSONObject result) {
// dismiss the dialog once product deleted
//Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
try {
if (result != null) {
Toast.makeText(getApplicationContext(),result.getString("message"),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
錯誤:必須將類AttemptLogin聲明為抽象或在'AsyncTask'中實現抽象方法'doInBackground(Params ...)
如果將doInBackground的參數更改為(Object []),它將起作用。 為什么我不能傳遞字符串值?
public class AttemptLogin extends AsyncTask<String, Void, JSONObject> {...}
將您的代碼更改為這樣
public class AttemptLogin extends AsyncTask<String,Void,JSONObject> {
...
您必須告訴AsyncTask您返回類型的類,否則默認為object
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.