Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid 1.6: "android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application"
    text
    copied!<p>I'm trying to open a dialog window, but every time I try to open it it throws this exception:</p> <pre><code>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) </code></pre> <p>I'm creating it by calling <code>showDialog</code> with the display's id. The <code>onCreateDialog</code> handler logs fine and I can step through it without an issue, but I've attached it since it seems like I'm missing something:</p> <pre><code>@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; } </code></pre> <p>Is there something missing from this? Some questions have talked about having this problem when creating a dialog from <code>onCreate</code>, which happens because the activity isn't created yet, but this is coming from a call from a menu object, and the <code>appContext</code> variable seems like it is correctly populated in the debugger.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload