简体   繁体   English

异常 java.lang.RuntimeException: setParameters 失败

[英]Exception java.lang.RuntimeException: setParameters failed

I am getting following error我收到以下错误

Exception java.lang.RuntimeException: setParameters failed
android.hardware.Camera.native_setParameters (Camera.java)
android.hardware.Camera.setParameters (Camera.java:1946)

in code below.在下面的代码中。 I have no clue what wrong i am doing below.我不知道我在下面做错了什么。

        Camera mCamera = Camera.open();
        Parameters params = mCamera.getParameters();

        if (params.getFlashMode() != null)
            params.setFlashMode(Parameters.FLASH_MODE_OFF);

        if (nightMode && params.getSceneMode() != null)
            params.setSceneMode(Parameters.SCENE_MODE_NIGHT);

        if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
            params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        } else if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
            params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        } else if (params.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
            params.setFocusMode(Parameters.FOCUS_MODE_INFINITY);
        }

        mCamera.setParameters(params);

this error is occurring in some devices like samsung mostly.此错误主要发生在三星等某些设备中。 Requesting for help.Thanks in advance.请求帮助。提前致谢。

Your params could be not supported by device.设备可能不支持您的参数。 You can detect available focus modes with getSupportedFocusModes method of Camera.Parameters class.您可以使用Camera.Parameters类的getSupportedFocusModes方法检测可用的对焦模式。 If some mode doesn't contain in this list, you can't set it to your camera.如果某些模式不包含在此列表中,则您无法将其设置为您的相机。

Edit编辑

As Alex said in comment you can see error message in logcat.正如亚历克斯在评论中所说,您可以在 logcat 中看到错误消息。

you must check if the focus mode supported by the user device, not all devices has camera focus mode, you do it like this:您必须检查用户设备是否支持对焦模式,并非所有设备都具有相机对焦模式,您可以这样做:

    public boolean support_focus(Camera camera){
     Camera.Parameters parameters = camera.getParameters();
     List<String> focusModes = parameters.getSupportedFocusModes();
     if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
         return true;
     else
         return false;
    }

this check if device support FOCUS_MODE_AUTO, change that with your desired Parameter.这个检查设备是否支持 FOCUS_MODE_AUTO,用你想要的参数改变它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Camera java.lang.RuntimeException:setParameters失败 - Camera java.lang.RuntimeException: setParameters failed E / AndroidRuntime(2671):java.lang.RuntimeException:setParameters失败 - E/AndroidRuntime( 2671): java.lang.RuntimeException: setParameters failed java.lang.RuntimeException:相机Api中的setParameters失败 - java.lang.RuntimeException: setParameters failed in Camera Api java.lang.RuntimeException:设置相机参数时,setParameters失败 - java.lang.RuntimeException: setParameters failed, while setting the camera parameters 相机关闭VM-java.lang.RuntimeException:setParameters失败 - Camera shutting down VM - java.lang.RuntimeException: setParameters failed java.Lang.RuntimeException,setParameters在android(4.1.1)版本中失败 - java.Lang.RuntimeException, setParameters failed in android(4.1.1) version java.lang.RuntimeException:Camera.setParameters - java.lang.RuntimeException: Camera.setParameters 相机应用程序可在模拟器上运行,但不能在真实设备上运行(阿尔卡特785 Smart 4 Mini)-java.lang.RuntimeException:setParameters失败 - Camera Application works on emulator but not real device (Alcatel 785 Smart 4 Mini) - java.lang.RuntimeException: setParameters failed 致命异常:java.lang.RuntimeException:takePicture失败 - FATAL EXCEPTION: java.lang.RuntimeException: takePicture failed 致命异常:java.lang.RuntimeException startPreview 失败 - Fatal Exception: java.lang.RuntimeException startPreview failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM