Java AlertBox-执行doInBackground()时出错 公共类IdAsync扩展异步任务{ AlertDialog AlertDialog=新建AlertDialog.Builder(MainClass.this).create(); 受保护的Void doInBackground(字符串…参数){ . . alertDialog.setTitle(“重置…”); 设置消息(“确定吗?”); alertDialog.setButton(“确定”,新的DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog,int which){ //在这里可以添加函数 } }); alertDialog.show(); . .}
这会导致运行时错误Java AlertBox-执行doInBackground()时出错 公共类IdAsync扩展异步任务{ AlertDialog AlertDialog=新建AlertDialog.Builder(MainClass.this).create(); 受保护的Void doInBackground(字符串…参数){ . . alertDialog.setTitle(“重置…”); 设置消息(“确定吗?”); alertDialog.setButton(“确定”,新的DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog,int which){ //在这里可以添加函数 } }); alertDialog.show(); . .},java,android,Java,Android,这会导致运行时错误 E/AndroidRuntime(16606):位于android.app.Dialog.show(Dialog.java:241)方法doInBackground用于执行后台任务。要更新AsyncTask中的UI,请使用onProgressUpdate方法。请参阅…方法doInBackground用于执行后台任务。要更新AsyncTask中的UI,请使用onProgressUpdate方法。请参阅…您应该执行onPostExecute、onPreExecute或onP>中的
E/AndroidRuntime(16606):位于android.app.Dialog.show(Dialog.java:241)方法doInBackground用于执行后台任务。要更新AsyncTask中的UI,请使用onProgressUpdate方法。请参阅…方法doInBackground用于执行后台任务。要更新AsyncTask中的UI,请使用onProgressUpdate方法。请参阅…您应该执行onPostExecute、onPreExecute或onP>中的对话框用于更新UI的AsyncTask的rogressUpdate方法。
不在doInBackGround中。您好,您应该在AsyncTask的onPostExecute、onPreExecute或onProgressUpdate方法中执行对话框以更新UI。 不在后台
public class IdAsync extends AsyncTask<String, Void, Void> {
AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create();
protected Void doInBackground(String... params) {
.
.
alertDialog.setTitle("Reset...");
alertDialog.setMessage("R u sure?");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//here you can add functions
} });
alertDialog.show();
.
.}