android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli

弹dialog是出现如下错误:
08-25 18:11:01.970: E/AndroidRuntime(24561): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.view.ViewRootImpl.setView(ViewRootImpl.java:589)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.app.Dialog.show(Dialog.java:293)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at com.ttdevs.easysecuritysmartbar.StartHandler.handleMessage(StartHandler.java:39)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.os.Looper.loop(Looper.java:137)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at android.app.ActivityThread.main(ActivityThread.java:4866)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-25 18:11:01.970: E/AndroidRuntime(24561): 	at dalvik.system.NativeStart.main(Native Method)


AlertDialog dialog = new AlertDialog.Builder(context).setTitle(title).setCancelable(false)
				.setPositiveButton("确定", listener).create();

其中context是通过getApplicationContext()获取的,将其换成Activity.this,问题解决


你可能感兴趣的:(android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli)