为什么我无法重写类中的 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> {...}
关于java - 无法覆盖 doInBackground 方法 (asyncTask),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40237004/