我正在使用Android Cardboard SDK
和RajawaliVR
(https://github.com/Rajawali/RajawaliVR)开发一个虚拟现实视频查看器。
在某些设备上,我在从睡眠状态返回时发生此崩溃(其他设备仅显示黑屏):
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.opengl.GLSurfaceView$GLThread.surfaceCreated()' on a null object reference
at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:523)
at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1970)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5891)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
正如你在android代码中看到的,如何开始调试它?
最佳答案
你可以访问源代码,所以从这个开始。
假设你用的是棒棒糖,那就失败了:
mGLThread.surfaceCreated();
错误消息指示
mGLThread
为空。使用web浏览器对作业(“mGLThread =
”)进行简单搜索会显示两个实例,其中最有趣的是on this line:public void setRenderer(Renderer renderer) {
...
mGLThread = new GLThread(mThisWeakRef);
撇开一些复杂性不谈,
mGLThread
应该是非空的,只要调用setRenderer()
。因此,首先要做的是检查应用程序是否正在调用setRenderer()
(通常在onCreate()
中)。