It seems that you device dows not support camera (or it is locked)

When I switch cameras using Android, this error occurs.
This is my code for switching cameras.

public void switchCam(){
        javaCameraView.disableView();
        if(isFrontCamera){
            //            javaCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_FRONT);
            lockCamId = Camera.CameraInfo.CAMERA_FACING_BACK;
            javaCameraView.setCameraIndex(lockCamId);
            isFrontCamera = false;
        }else{
            lockCamId = Camera.CameraInfo.CAMERA_FACING_FRONT;
            javaCameraView.setCameraIndex(lockCamId);
            isFrontCamera=true;
        }

        javaCameraView.enableView();
    }

I will first use this to start my camera

JavaCameraView javaCameraView = new JavaCameraView(context,CameraBridgeViewBase.CAMERA_ID_ANY);

Of course, I also thought of using CameraBridgeViewBase.CAMERA_ID_FRONT or CameraBridgeViewBase.CAMERA_ID_BACK

This way, it is more likely to trigger errors in the title. How should I correctly and reasonably switch cameras

At first, this code ran normally, but when I unplugged the USB camera or replaced it (when exiting the application), I would receive an error message with the title .Attempting to restart the application or Android device cannot effectively resolve the issue.

OpenCVSDK 4.9.0

Are those OpenCV APIs? They look like Android APIs.

Yes, these APIs are all from opencv-4.9.0-android-sdk

they appear to be very new. I can’t even navigate to these APIs from the API docs.

All I found was this tutorial, which claims to be valid only from v4.9 onwards.

https://docs.opencv.org/4.x/d5/df8/tutorial_dev_with_OCV_on_Android.html

Thank you for providing documentation assistance

Your document is the simplest example, and I just tried to rebuild it by directly specifying the camera ID (front or rear) without using custom switching. It was found that only the rear camera can function properly, while the front camera cannot function, Tip title error. The front camera is a USB camera. My Android device is the source version of the Android system, which is Android 11

But when I unplug the USB camera, I first start a working camera, then wait for a moment to plug in the USB camera, exit the application, and restart to switch back to the USB camera. Does this require repeated operations to succeed? May I ask if this is a bug or a problem with my application?