java - App crashes by opening spinner on popup -
i got massive problem spinner. popup appears without problem , it's showing spinner in closed position.
but when open it, app crashes following error message...
04-10 08:34:33.773 1690-1690/com.example.paul_io e/androidruntime﹕ fatal exception: main process: com.example.paul_io, pid: 1690 android.view.windowmanager$badtokenexception: unable add window -- token android.view.viewrootimpl$w@52f02170 not valid; activity running? @ android.view.viewrootimpl.setview(viewrootimpl.java:532) @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:259) @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) @ android.widget.popupwindow.invokepopup(popupwindow.java:1019) @ android.widget.popupwindow.showasdropdown(popupwindow.java:925) @ android.widget.listpopupwindow.show(listpopupwindow.java:625) @ android.widget.spinner$dropdownpopup.show(spinner.java:1110) @ android.widget.spinner.performclick(spinner.java:658) @ android.view.view$performclick.run(view.java:18422) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method)
what i´ve done wrong?
significant code:
variables.mainactivity = mainactivity.this; . . . activity mcontext = variables.mainactivity; spinner ecb = new spinner(mcontext);
the problem context passed (badtokenexception
).
i think using getapplicationcontext()
.instead use youractivityname.this
passing context