Android 1.6: "android.view.WindowManager$BadTokenException: Unable to add window -- token null is no
Posted
by Dan Monego
on Stack Overflow
See other posts from Stack Overflow
or by Dan Monego
Published on 2010-04-14T04:55:13Z
Indexed on
2010/04/14
17:23 UTC
Read the original article
Hit count: 3669
android
I'm trying to open a dialog window, but every time I try to open it it throws this exception:
E/AndroidRuntime( 206): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 206): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime( 206): at android.view.ViewRoot.setView(ViewRoot.java:460)
E/AndroidRuntime( 206): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
E/AndroidRuntime( 206): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/AndroidRuntime( 206): at android.app.Dialog.show(Dialog.java:238)
E/AndroidRuntime( 206): at android.app.Activity.showDialog(Activity.java:2413)
I'm creating it by calling showDialog with the display's id. The onCreateDialog handler logs fine and I can step through it without an issue, but I've attached since it seems like I'm missing something in it:
@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;
}
Is there something missing from this? Some questions have talked about having this problem when creating a dialog from onCreate, which happen because the activity isn't created yet, but this is coming from a call from a menu object, and the appContext variable seems like it is correctly populated in the debugger.
© Stack Overflow or respective owner