Skip to content Skip to sidebar Skip to footer

'android.view.SurfaceHolder Android.view.SurfaceView.getHolder()' On A Null Object Reference In SurfaceView

I am trying to show a camera preview in a dialogue. Every time I try to run the app I have the following error: java.lang.RuntimeException: Unable to start activity ComponentInfo{c

Solution 1:

change camera class to this:

public class CameraExample extends AnimatedViewContainer {

private final static String TAG = "CameraExample";

private Context mContext;
private SurfaceView mPreview;
public CameraExample(Context context, int i) {
    super(context, i);
    mContext = context;

}

@Override
public void onCreateViewContent(LayoutInflater layoutInflater, ViewGroup parentGroup, View[] containerViews, int index) {
    containerViews[index] = layoutInflater.inflate(R.layout.example_camera, parentGroup, false);
    FrameLayout previewFrame = (FrameLayout) containerViews[index].findViewById(R.id.preview);

    //this have been line moved here from constructor 
    mPreview = (SurfaceView) findViewById(R.id.surfaceView);
    CameraPreview mgr = new CameraPreview(mContext, mPreview);
    mgr.init();

    // Add preview for inflation
    previewFrame.addView(mPreview);

}

}


Post a Comment for "'android.view.SurfaceHolder Android.view.SurfaceView.getHolder()' On A Null Object Reference In SurfaceView"