我正在使用Android Cardboard SDK
和RajawaliVR
(https://github.com/Rajawali/RajawaliVR)开发VR视频查看器
在某些设备上,我从睡眠状态返回时出现此故障(其他设备只显示黑屏):
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代码中,我该如何开始调试呢?
答案 0 :(得分:7)
您可以访问源代码,因此请从此开始。
假设你正在使用Lollipop,它失败了on this line:
Handler
错误消息表明mGLThread.surfaceCreated();
为空。使用Web浏览器对分配进行简单搜索(“mGLThread
”)会显示两个实例,其中最有趣的是this one:
mGLThread =
除了设置一些复杂性之外,只要调用public void setRenderer(Renderer renderer) {
...
mGLThread = new GLThread(mThisWeakRef);
,mGLThread
就应该是非空的。因此,首先要检查您的应用程序是否正在调用setRenderer()
(通常在setRenderer()
中)。
答案 1 :(得分:3)
如果您按照Python/ceval.c进行操作,Android Studio可能会在您的Activity类构造函数中更正此定义:
mGLView = new MyGLSurfaceView(this);
并将其更改为
mGLView = new GLSurfaceView(this);
因为类MyGLSurfaceView尚未编码...跳过MyGLSurfaveView构造函数,这是调用setRenderer(...)的地方。法登先生的回答非常好,解释了如何诊断问题。