Search code examples
androidparametersandroid-cameravideo-capture

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.


Solution

  • Your params could be not supported by device. You can detect available focus modes with getSupportedFocusModes method of Camera.Parameters class. 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.