我有一个 AsyncTask 类。当我遇到错误时,我想看到一条 toast 消息。这是我的 AsynTask 类:
private GetUtenti threadutenti;
threadutenti= (GetUtenti) new GetUtenti(this.getActivity()).execute();
这是我的课:
class GetUtenti extends AsyncTask<Void, Void, Void> {
private Context context;
private boolean errore = false;
private Database db;
public GetUtenti(Context context){
this.context=context;
}
@Override
protected void onPostExecute(Void result) {
db.disconnetti();
if (errore) {
Toast.makeText(context, "error!", Toast.LENGTH_SHORT)
toast.show();
}
else{
setListaUtenti();
}
bProgresso.dismiss();
}
@Override
protected void onPreExecute() {
db = new Database(.....);
}
@Override
protected Void doInBackground(Void... params) {
db.connetti();
if(!db.isConnesso()){
errore= true;
} else {
utenti.clear();
utenti = Utente.getUtenti(db);
}
return null;
}
}
当我想查看我的 Toast 消息时,我有这个:
03-04 17:41:06.534: E/AndroidRuntime(13622): FATAL EXCEPTION: main
03-04 17:41:06.534: E/AndroidRuntime(13622): java.lang.RuntimeException: This Toast was not created with Toast.makeText()
03-04 17:41:06.534: E/AndroidRuntime(13622): at android.widget.Toast.setText(Toast.java:282)
03-04 17:41:06.534: E/AndroidRuntime(13622): at com.unipg.utente.ListUtente$GetUtenti.onPostExecute(ListUtente.java:145)
为什么?