我试图打开一个对话框窗口,但是每次我尝试打开它时,都会引发此异常:
Uncaught handler: thread main exiting due to uncaught exception
android.view.WindowManager$BadTokenException:
Unable to add window -- token null is not for an application
at android.view.ViewRoot.setView(ViewRoot.java:460)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.app.Dialog.show(Dialog.java:238)
at android.app.Activity.showDialog(Activity.java:2413)
我通过showDialog
使用显示器的ID 进行调用来创建它。该onCreateDialog
处理程序的日志记录很好,我可以毫无问题地逐步解决它,但是我附上了它,因为似乎我缺少了一些东西:
@Override
public Dialog onCreateDialog(int id)
{
Dialog dialog;
Context appContext = this.getApplicationContext();
switch(id)
{
case RENAME_DIALOG_ID:
Log.i("Edit", "Creating rename dialog...");
dialog = new Dialog(appContext);
dialog.setContentView(R.layout.rename);
dialog.setTitle("Rename " + noteName);
break;
default:
dialog = null;
break;
}
return dialog;
}
这还缺少什么吗?一些问题涉及从创建对话框时出现此问题onCreate
,这是由于尚未创建活动而发生的,但这是来自菜单对象的调用,并且该appContext
变量似乎已在调试器中正确填充。