PopupWindow $BadTokenException: Unable to add window -- token null is not valid
Solution 1:
Same problem happened with me when I try to show a popup menu in an activity.
I also got the same exception but I encountered problems and resolved it by providing the right context.
// at this line
Dialog dialog = new Dialog(getApplicationContext());
Use
YourActivityName.this
instead of getApplicationContext()
and yes it worked for me may it will help someone else.
Solution 2:
you are showing your popup too early. You may post a delayed runnable for showatlocation in Onresume , Give it a try
Edit: This post seems to have the same problem answered Problems creating a Popup Window in Android Activity