Skip to content Skip to sidebar Skip to footer

App Crashing While Trying To Take New Photo

I am developing a customized camera app. when app starts camera opens there are three buttons at bottom. Capture (To take picture). Take New (return from preview to camera to tak

Solution 1:

It might because of You have taken the photo first time succesfully and acquire the camera object then again you are acquiring the camera object here.

First instance here below setcontentview.

// Create an instance of Camera

mCamera = getCameraInstance();

and trying to acquire camera instance again but its already acquired.

btn_new = (Button) findViewById(R.id.button_new);
btn_new.setOnClickListener(newView.OnClickListener() {

    @OverridepublicvoidonClick(View v) {

        mCamera = getCameraInstance();

        //preview = (FrameLayout) findViewById(R.id.camera_preview);//preview.addView(mPreview);
    }
});

Before acquire the camera object again you should have release the first one it.

if(mCamera != null)
   mCamera.release();

and

Make ensure you have declare permission in manifest before application tag.

Solution 2:

Well the null pointer exception is coming from your exception. you have

Contextcontext=null; 

and then you are trying to use it here:

Toast.makeText(context.getApplicationContext(),"Camera is not available" ,           Toast.LENGTH_LONG).show();

without acutally initializing it anywhere.

Also in you onPause() function you should clean up after yourself. (eg. release camera, stop surface preview, that sort of thing).

Post a Comment for "App Crashing While Trying To Take New Photo"