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 4266844
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:49:00+00:00 2026-05-21T06:49:00+00:00

Hi guys I am using the following code to access Camera from my application

  • 0

Hi guys
I am using the following code to access Camera from my application :-

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    isPreviewRunning = false;
    surface = (SurfaceView)findViewById(R.id.surface);
    holder = surface.getHolder();
  holder.addCallback(this);


}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    if (isPreviewRunning) {  
          camera.stopPreview();  
         }  

     Camera.Parameters p = camera.getParameters();  
     p.setPreviewSize(480, 800);  
     p.setPictureFormat(PixelFormat.JPEG);
     camera.setParameters(p); 

     try {
        camera.setPreviewDisplay(holder);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  
     camera.startPreview();  
     isPreviewRunning=true;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
     camera = Camera.open();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera.stopPreview();
    camera.release();
    camera=null;
}

I get force close and the error in log cat is following :-

04-13 15:21:36.979: ERROR/AndroidRuntime(14583): FATAL EXCEPTION: main
04-13 15:21:36.979: ERROR/AndroidRuntime(14583): java.lang.RuntimeException: setParameters failed
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.hardware.Camera.native_setParameters(Native Method)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.hardware.Camera.setParameters(Camera.java:655)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at org.mycamera.mycamera.surfaceChanged(mycamera.java:44)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.SurfaceView.updateWindow(SurfaceView.java:546)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.View.draw(View.java:6742)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.View.draw(View.java:6742)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1872)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewRoot.draw(ViewRoot.java:1422)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1167)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.os.Looper.loop(Looper.java:144)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at android.app.ActivityThread.main(ActivityThread.java:4937)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at java.lang.reflect.Method.invokeNative(Native Method)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at java.lang.reflect.Method.invoke(Method.java:521)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-13 15:21:36.979: ERROR/AndroidRuntime(14583):     at dalvik.system.NativeStart.main(Native Method)
  • 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-05-21T06:49:01+00:00Added an answer on May 21, 2026 at 6:49 am

    You will have to use one of the supported picture sizes:

    Camera.Parameters p = camera.getParameters();
    List<Size> sizes = p.getSupportedPictureSizes();
    // Choose any one you want among sizes
    size = sizes.get(0);
    p.setPictureSize(size.width, size.height);
    camera.setParameters(p);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Guys i am using following code to get the uploaded image $imagedata= 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
Guys i have used the following code to disable an option using jQuery (
Hi guys lets say I have the following html: <div class=owner> <div> <a href=javascript:void(0)
Hey guys, I'm building an application which requires access to the server time before
Hey guys I have the following code working which is sending a GET Request
guys, I have the following code, but I'm getting error at compiling time... the
What do you guys think about this for a generic singleton? using System; using
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
I had been using the header() a lot in my application to redirect to

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.