【发布时间】:2016-12-27 07:58:35
【问题描述】:
它表示 Async 不会覆盖超类中的任何方法。 这是取自 tutorialspoint 网站的示例。 这似乎不起作用。请帮忙。 提前致谢。 *编辑:我已经上传了完整的 java 文件。
public class SigninActivity extends AsyncTask{
private Context context;
private TextView statusField,userField;
public SigninActivity(Context context,TextView statusField,TextView userField) {
this.context = context;
this.statusField = statusField;
this.userField = userField;
}
protected void onPreExecute(){
}
@Override
protected String doInBackground(String... arg0) {
try{
String username = (String)arg0[0];
String password = (String)arg0[1];
String link="http://127.0.0.1/login.php";
String data = URLEncoder.encode("username", "UTF-8") + "=" +
URLEncoder.encode(username, "UTF-8");
data += "&" + URLEncoder.encode("password", "UTF-8") + "=" +
URLEncoder.encode(password, "UTF-8");
URL url = new URL(link);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write( data );
wr.flush();
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null) {
sb.append(line);
break;
}
return (sb.toString());
}
catch(Exception e){
return (new String("Exception: " + e.getMessage()));
}
}
@Override
protected void onPostExecute(String result){
this.statusField.setText("Login Successful");
this.userField.setText(result);
}
}
【问题讨论】:
-
你要扩展哪个类
-
我猜你没有为
AsyncTask使用正确的类型参数——但我们看不到,因为你只提供了方法,而不是minimal reproducible example。 -
我正在扩展 AsyncTask@Mr.Popular
-
发布您的完整异步任务类代码..
-
@NitinMamidala。我们还需要类型。你必须有类似
AsyncTask<String, Void, String>的东西。该部分在您的代码中是什么样的?
标签: java android asynchronous android-asynctask overriding