尝试在空对象引用上调用虚拟方法 'void android.opengl.GLSurfaceView$GLThread.surfaceCreated()'

Attempt to invoke virtual method 'void android.opengl.GLSurfaceView$GLThread.surfaceCreated()' on a null object reference

我是 google Cardboard 的新手,正在尝试实现这个 example。我已正确包含 .aar 文件并在启动时发现此运行时异常。请建议如何解决此问题,并建议在何处获得 google cardboard 的基本启动(如果可能的话)。

非常感谢你在这个话题上帮助我。

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:556)
                                                           at android.view.SurfaceView.updateWindow(SurfaceView.java:675)
                                                           at android.view.SurfaceView.onPreDraw(SurfaceView.java:202)
                                                           at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
                                                           at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2357)
                                                           at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1301)
                                                           at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6673)
                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:603)
                                                           at android.view.Choreographer.doFrame(Choreographer.java:572)
                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
                                                           at android.os.Handler.handleCallback(Handler.java:815)
                                                           at android.os.Handler.dispatchMessage(Handler.java:104)
                                                           at android.os.Looper.loop(Looper.java:194)
                                                           at android.app.ActivityThread.main(ActivityThread.java:5637)
                                                           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:959)
                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

MainActivity.java

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.widget.ImageView;

import com.google.vr.sdk.base.Eye;
import com.google.vr.sdk.base.GvrActivity;
import com.google.vr.sdk.base.GvrView;
import com.google.vr.sdk.base.HeadTransform;
import com.google.vr.sdk.base.Viewport;

import javax.microedition.khronos.egl.EGLConfig;

public class MainActivity extends GvrActivity implements
        GvrView.StereoRenderer {

    private static final String TAG = "MainActivity2";

    Uri fileUri = null;
    ImageView photoImage = null;

    private Vibrator mVibrator;

    private int mScore = 0;

    private CardboardOverlayView mOverlayView;

    public MainActivity() {
    }

    /**
     * Sets the view to our CardboardView and initializes the transformation
     * matrices we will use to render our scene. //@param savedInstanceState
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.content_main);

        GvrView cardboardView = (GvrView) findViewById(R.id.cardboard_view1);

        setGvrView(cardboardView);

        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

        mOverlayView = (CardboardOverlayView) findViewById(R.id.overlay);

        mOverlayView.show3DSplashImage();

        mOverlayView.show3DImage(mScore++, MainActivity.this);
        mVibrator.vibrate(50);


    }

    protected void onNfcIntent(Intent intent) {

    }

    @Override
    public void onRendererShutdown() {
        Log.i(TAG, "onRendererShutdown");
    }

    @Override
    public void onSurfaceChanged(int width, int height) {
        Log.i(TAG, "onSurfaceChanged");
    }

    @Override
    public void onSurfaceCreated(EGLConfig eglConfig) {
        Log.i(TAG, "onSurfaceCreated");
    }


    /**
     * Creates the buffers we use to store information about the 3D world.
     * OpenGL doesn't use Java arrays, but rather needs data in a format it can
     * understand. Hence we use ByteBuffers.
     *
     * @param config
     *            The EGL configuration used when creating the surface.
     */


    /*@Override
    public void onCardboardTrigger() {
        Log.i(TAG, "onRendererShutdown1");

        mOverlayView.show3DImage(mScore++, MainActivity.this);
        mVibrator.vibrate(50);
    }*/

    /**
     * Prepares OpenGL ES before we draw a frame.
     *
     * @param headTransform
     *            The head transformation in the new frame.
     */
    @Override
    public void onNewFrame(HeadTransform headTransform) {
    }

    @Override
    public void onDrawEye(Eye eye) {

    }

    /**
     * Draws a frame for an eye. The transformation for that eye (from the
     * camera) is passed in as a parameter.
     *
     * @param viewport
     *            The transformations to apply to render this eye.
     */


    @Override
    public void onFinishFrame(Viewport viewport) {
    }

    public void onRemovedFromCardboard() {
        Log.d("vbv", "msg");
    }
}

CardboardOverlayView.java 是扩展的线性布局 class。

我错过了什么

GvrView cardboardView = (GvrView) findViewById(R.id.cardboard_view1);

        cardboardView.setRenderer(this);