Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

android - BadTokenException

i start a activity,i need to show a alertdialog,so i write a dialog util class(dialoghandler) ,i pass the context to the dialoghandler ,the first start is ok,but when i start the second ,it happend the exception.what should i do,ps help me.

here is the bug report:

12-03 07:23:26.000: ERROR/AndroidRuntime(21525): FATAL EXCEPTION: main
12-03 07:23:26.000: ERROR/AndroidRuntime(21525): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at android.view.ViewRoot.setView(ViewRoot.java:509)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at android.app.Dialog.show(Dialog.java:241)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at com.eoemobile.api.update.EoeSdkUpdate.onCacheFetched(EoeSdkUpdate.java:170)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at com.eoemobile.api.net.CacheManager.handleCallBackMag(CacheManager.java:362)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at com.eoemobile.api.net.CacheManager.access$1(CacheManager.java:358)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at com.eoemobile.api.net.CacheManager$CallbackHandler.handleMessage(CacheManager.java:375)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at android.os.Looper.loop(Looper.java:123)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at java.lang.reflect.Method.invokeNative(Native Method)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at java.lang.reflect.Method.invoke(Method.java:521)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-03 07:23:26.000: ERROR/AndroidRuntime(21525):     at dalvik.system.NativeStart.main(Native Method)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot display an application window/dialog through a Context that is not an Activity. Check please that every time you start a dialog it gets correct Context.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...