I get the following Android exception when I try to open a dialog. Can someone please help me understand what is going on and how can I fix this problem?
android.view.WindowManager$BadTokenException:
Unable to add window -- token null is not for an application
at android.view.ViewRoot.setView(ViewRoot.java:509)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.app.Dialog.show(Dialog.java:241)
I'm guessing - are you trying to create Dialog with an application context? Something like this:
new Dialog(getApplicationContext());
This is wrong. You need to use an Activity context.
You have to try like:
new Dialog(YourActivity.this);