Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.RuntimeException: setParameters failed in Camera Api

Tags:

android

camera

I am developing Camera overly app in that i am using camera api for preview and overlay effects.I am getting force close error in some mobiles and it is not happening other mobiles.

My code:

parameters = camera.getParameters(); 
List<Size> sizes = parameters.getSupportedPreviewSizes(); 
Size optimalSize = getOptimalPreviewSize(sizes, w, h); 
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
parameters.setColorEffect(Camera.Parameters.EFFECT_SOLARIZE);
setCameraDisplayOrientation(MainActivity.this,0, camera); 
camera.getParameters(); 
camera.setParameters(parameters);

These are the call stacks I am getting

    java.lang.RuntimeException: setParameters failed
    at android.hardware.Camera.native_setParameters(Native Method)
    at android.hardware.Camera.setParameters(Camera.java:1046)
    at com.androidpixels.watercamera.MainActivity.surfaceChanged(MainActivity.java:1241)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:575)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:407)
    at android.view.SurfaceView.dispatchDraw(SurfaceView.java:352)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    at android.view.View.draw(View.java:6936)
    at android.widget.FrameLayout.draw(FrameLayout.java:357)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1917)
    at android.view.ViewRoot.draw(ViewRoot.java:1530)
    at android.view.ViewRoot.performTraversals(ViewRoot.java:1266)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3693)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
    at dalvik.system.NativeStart.main(Native Method)

Please help me. what could be the reason?

like image 841
VR.Naresh Avatar asked Feb 06 '13 13:02

VR.Naresh


1 Answers

Android Camera Parameters vary between devices. you need to verify that the device supports the parameter you're trying to set before setting it, see this Camera SetParameters Doc

You can query the Supported Parameters by :

  • Obtain a Parameters object : Camera.Parameters params = mCamera.getParameters();
  • Then query that object for specific Parameter , say PreviewSize:

    params.getSupportedPreviewSizes ()

like image 135
Mr.Me Avatar answered Oct 23 '22 19:10

Mr.Me