且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用的ViewGroup抛出NullPointerException异常

更新时间:2023-11-19 12:25:46

此错误使用在我们的一些规律性的崩溃报告露面。这是非常难以追查,但最终我们发现,我们有时触发了删除从视图层次从surfaceDestroyed视图code()(从SurfaceHolder回调方法)。如果您的应用使用SurfaceView,确保你没有做任何修改视图层次结构surfaceDestroyed()。

Does anyone have a clue what could be causing this?

11-16 16:23:26.745: ERROR/AndroidRuntime(9549): Uncaught handler: thread main exiting due to uncaught exception
11-16 16:23:26.765: ERROR/AndroidRuntime(9549): java.lang.NullPointerException
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:692)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:692)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at android.view.ViewRoot.performTraversals(ViewRoot.java:722)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at android.os.Looper.loop(Looper.java:123)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at android.app.ActivityThread.main(ActivityThread.java:4363)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at java.lang.reflect.Method.invokeNative(Native Method)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at java.lang.reflect.Method.invoke(Method.java:521)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
11-16 16:23:26.765: ERROR/AndroidRuntime(9549):     at dalvik.system.NativeStart.main(Native Method)

This error used to show up in our crash reports with some regularity. It was very difficult to track down, but in the end we discovered that we sometimes triggered code that removed a view from the view hierarchy from surfaceDestroyed() (the callback method from SurfaceHolder). If your app is using a SurfaceView, make sure you don't do anything to modify the view hierarchy in surfaceDestroyed().