Skip to content Skip to sidebar Skip to footer

.setpreviewdisplay(holder) Throwing Null Pointer Exception

I am developing a custom camera application.Given below is my Activity class. public class MyCustomCam extends Activity { private Camera mCamera; private CameraPreview mPreview

Solution 1:

Release the camera in your surfaceDestroyed function

publicvoidsurfaceDestroyed(SurfaceHolder holder) {
        if (mCamera != null) {
        mCamera.stopPreview();
        mCamera.release();
        mCamera = null;   
} 

and make sure you add camera permission in your manifest file.

<uses-permissionandroid:name="android.permission.CAMERA" />

Solution 2:

I was having the same bug.

I used this Q&A to help solve my issue. Specifically, reference the adding of the function getBestPreviewSize(...) invoked prior to params.setPreviewSize(...) being set in surfaceChanged.

Android - cam.setPreviewDisplay(holder) running into IOError

As a side note (because this was my next bug), if you start doing any more customization of the Layout (e.g. removing the title bar), any "requests" to the UI to make changes should be made prior to setContentView(...), noted in the link below.

requestFeature() must be called before adding content

Solution 3:

Most probably your problem would be that your emulator's camera settings. Go to AVD manager, edit your emulator and set your camera , may be to emulated. restart the emulator and launch your app.

Post a Comment for ".setpreviewdisplay(holder) Throwing Null Pointer Exception"