私はAlertDialogを作成するために次のコードを使用しました。androidのAlertDialogエラー
02-03 11:36:43.204: WARN/dalvikvm(452): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
02-03 11:36:43.214: ERROR/AndroidRuntime(452): Uncaught handler: thread main exiting due to uncaught exception
02-03 11:36:43.234: ERROR/AndroidRuntime(452): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
02-03 11:36:43.234: ERROR/AndroidRuntime(452): at android.view.ViewRoot.setView(ViewRoot.java:472)
02-03 11:36:43.234: ERROR/AndroidRuntime(452): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
このクラスは活動
public class HomeTabActivity extends Activity
です
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
しかし、それは私が得たエラーalert.show()
上のエラーを示しこれはHomeTabActivityある各を使用して、私から1 groupActivityですアクティビティとしてタップします。 私は私が何を逃したこの
View view = getLocalActivityManager().startActivity("hometab", new
Intent(this,HomeTabActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
replaceView(view);
のようにこの活動を呼びました。事前に感謝
を使用してみてくださいする必要があります)、それは対話を続けていくつかの魔法をしているため、より良いですアクティビティが再作成されても(画面を回転させるなど)、画面上に表示されます。しかし、それはあなたのエラーとは何の関係もありません(Zelimirの答えを参照)。 –
あなたは正しいです。私はちょうど彼が現在の問題を解決するのを手助けしたかった。画面の回転に関連するAlertDialogの魔法を管理することは、onSaveInstanceState()に保存され、onCreate()で回復されるブール値のメーターに過ぎません。 – Zelimir