这是我的 AsyncTask 类
private class UpdatingNews extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
webservice.UpdateAllNews();
webservice.updateallCatNews();
return null;
}
@Override
protected void onPostExecute(String result) {
}
}
我叫它
UpdatingNewsupdate = new UpdatingNews();
update.execute();
它确实执行。然后我想在单击按钮时检查此任务的状态是否完成,所以我像这样检查。
if (update.getStatus().toString()
.equals(AsyncTask.Status.FINISHED.toString())) {
toast = Toast.makeText(Main_FormNewUser.this,
"Thanks for fill in our survey form!",
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL
| Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
name = nametext.getText().toString();
email = emailtext.getText().toString();
webservice.InsertSurvey(name, email, ages, genders,
jobs, salaries, interesting);
webservice.insertFormSubmit(1);
startActivity(new Intent(Main_FormNewUser.this,
Main_AllLatestNews.class));
finish();
}
单击后,它将启动 Main_AllLatestNews.class 但出现 NullPointerException。
我尝试不使用 AsyncTask 并且没有返回错误,我不知道为什么我调用 AsyncTask 它会给我错误?