Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:41:29+00:00 2026-06-15T17:41:29+00:00

My application has a camera functionality. It works fine in all Android version but

  • 0

My application has a camera functionality. It works fine in all Android version but now when i tested in S3 it crashes. The error points to this line:

Parameters parameters = mCamera.getParameters();

In:

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    // Log.e(TAG, "surfaceChanged");
    // XXX stopPreview() will crash if preview is not running
    if (mPreviewRunning) {
        mCamera.stopPreview();
    }

    /**
     * CODE TO RESOLVE CAMERA ORIENTATION PROBLEM START
     */

    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
            .getDefaultDisplay();
    int flashStatus = session1.getFlashStatus();
    Parameters parameters = mCamera.getParameters();
    if (flashStatus == 0) {
        btnFlash.setBackgroundResource(R.drawable.flash);
        parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
        mCamera.setParameters(parameters);
    } else if (flashStatus == 1) {
        btnFlash.setBackgroundResource(R.drawable.flash_on);
        parameters.setFlashMode(Parameters.FLASH_MODE_ON);
        mCamera.setParameters(parameters);
    } else {
        btnFlash.setBackgroundResource(R.drawable.flash_off);
        parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
        mCamera.setParameters(parameters);
    }
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;

    if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO) {
        // Do something for froyo and above versions
        if (display.getRotation() == Surface.ROTATION_0) {
            // parameters.setPreviewSize(h, w);
            mCamera.setDisplayOrientation(90);
        }
        if (display.getRotation() == Surface.ROTATION_90) {
            // parameters.setPreviewSize(w, h);
        }
        if (display.getRotation() == Surface.ROTATION_180) {
            // parameters.setPreviewSize(h, w);
            mCamera.setDisplayOrientation(-90);
        }
        if (display.getRotation() == Surface.ROTATION_270) {
            // parameters.setPreviewSize(w, h);
            mCamera.setDisplayOrientation(90);
        }
    } else {
        // do something for phones running an SDK before level 9
        if (display.getOrientation() == Surface.ROTATION_0) {
            // parameters.setPreviewSize(h, w);
            mCamera.setDisplayOrientation(90);
        }
        if (display.getOrientation() == Surface.ROTATION_90) {
            mCamera.setDisplayOrientation(90);
            // parameters.setPreviewSize(w, h);
        }
        if (display.getOrientation() == Surface.ROTATION_180) {
            mCamera.setDisplayOrientation(90);
            // parameters.setPreviewSize(h, w);
        }
        if (display.getOrientation() == Surface.ROTATION_270) {
            mCamera.setDisplayOrientation(90);
            // parameters.setPreviewSize(w, h);
            // mCamera.setDisplayOrientation(180);
        }
    }

    mCamera.setParameters(parameters);
    /**
     * CODE TO RESOLVE CAMERA ORIENTATION PROBLEM END
     */
    try {
        mCamera.setPreviewDisplay(mSurfaceHolder);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (mPreviewRunning) {
        mCamera.stopPreview();
        mCamera.startPreview();
        mPreviewRunning = true;
    } else {
        mCamera.startPreview();
        mPreviewRunning = true;
    }

}

public void surfaceDestroyed(SurfaceHolder holder) {
    Log.e(TAG, "surfaceDestroyed");
    if (mPreviewRunning) {
        mCamera.stopPreview();
        mPreviewRunning = false;
        mCamera.release();
    }
}

Could someone provide a solution for this? The log is below:

?:??: W/?(?): java.lang.NullPointerException
?:??: W/?(?):   at com.stpl.snapshun.camera.CameraActivity.surfaceChanged(CameraActivity.java:313)
?:??: W/?(?):   at android.view.SurfaceView.updateWindow(SurfaceView.java:554)
?:??: W/?(?):   at android.view.SurfaceView.access$000(SurfaceView.java:81)
?:??: W/?(?):   at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
?:??: W/?(?):   at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:671)
?:??: W/?(?):   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1818)
?:??: W/?(?):   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
?:??: W/?(?):   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
?:??: W/?(?):   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
?:??: W/?(?):   at android.view.Choreographer.doCallbacks(Choreographer.java:555)
?:??: W/?(?):   at android.view.Choreographer.doFrame(Choreographer.java:525)
?:??: W/?(?):   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
?:??: W/?(?):   at android.os.Handler.handleCallback(Handler.java:615)
?:??: W/?(?):   at android.os.Handler.dispatchMessage(Handler.java:92)
?:??: W/?(?):   at android.os.Looper.loop(Looper.java:137)
?:??: W/?(?):   at android.app.ActivityThread.main(ActivityThread.java:4745)
?:??: W/?(?):   at java.lang.reflect.Method.invokeNative(Native Method)
?:??: W/?(?):   at java.lang.reflect.Method.invoke(Method.java:511)
?:??: W/?(?):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
?:??: W/?(?):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
?:??: W/?(?):   at dalvik.system.NativeStart.main(Native Method)

My issue here is trying to access camera parameters returns null.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:41:29+00:00Added an answer on June 15, 2026 at 5:41 pm

    Lincy Here is Code of Class Camera View

     public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) 
    {   
        if(mPreviewRunning )
        {
            mCamera.stopPreview();
        }
    
        // Store width and height
        mWidth = width;
        mHeight = height;
    
        // Set camera parameters
        Camera.Parameters p = mCamera.getParameters();
        mCamera.setParameters(p);
    
        if(android.os.Build.VERSION.SDK_INT >= 8)
        {   // If API >= 8 -> rotate display...
            mCamera.setDisplayOrientation(90);
        }
    
        try
        {
            mCamera.setPreviewDisplay(holder);
        } catch(IOException e)
        {
            e.printStackTrace();
        }
    
        mCamera.startPreview();
        mPreviewRunning = true;
    
    }
     public void surfaceCreated(final SurfaceHolder holder) 
    {
        try {
            mCamera = Camera.open();
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) 
        {
            mCamera.release();
            mCamera = null;
            e.printStackTrace();
        }
    }
    
    public void surfaceDestroyed(SurfaceHolder holder) 
    {
        if(mCamera != null)
        {
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();
            mCamera.setPreviewCallback(null);
            mPreviewRunning = false;
            mCamera.release();
            mCamera = null;
        }   
    }
    

    one more Thing have you Implemented your class Using

    SurfaceHolder.Callback

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If an application has the android.permission.CAMERA, and I wanted my app to block the
I am developing application which has camera functionality. i want to save that captured
My application has one activity which starts two services but does not bind them.
I am developing the camera module for an android application. In main application when
The application currently I am using has a main functionality to scan QR/Bar codes
I have an Android Application that has the AndroidManifest.xml listed below. After uploading to
Can I take a picture from the front camera? My application has an input
I am developing an application in which I have to block android default camera
i did an application which has imageview to capture image from camera and a
I implemented the application for getting image from the camera album in sdcard.But it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.