无法解析空指针

时间:2015-02-16 04:42:54

标签: android

     02-16 10:10:48.126: E/AndroidRuntime(9838): FATAL EXCEPTION: main
02-16 10:10:48.126: E/AndroidRuntime(9838): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:810)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:265)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:73)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.app.Dialog.show(Dialog.java:282)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at com.example.printing.adapter$1.onClick(adapter.java:335)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.view.View.performClick(View.java:4452)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.view.View$PerformClick.run(View.java:18428)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.os.Handler.handleCallback(Handler.java:725)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.os.Looper.loop(Looper.java:176)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at android.app.ActivityThread.main(ActivityThread.java:5365)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at java.lang.reflect.Method.invokeNative(Native Method)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at java.lang.reflect.Method.invoke(Method.java:511)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-16 10:10:48.126: E/AndroidRuntime(9838):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

与日志一样:

  

WindowManager $ BadTokenException:无法添加窗口 - 令牌null为   不适用于申请

表示当前正在将getApplicationContext()传递给Dialog constroctor以创建Dialog对象。

使用当前用户可见的实时组件上下文来创建Dialog对象。

如果在活动中创建对话框,则使用CurrentActivityName.this代替getApplicationContext()

或者如果在任何视图中使用onClick内部方法,则使用onClick方法参数来获取if onClick(View view)之类的上下文,然后使用view.getContext()获取上下文