Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1

This error occurs when using CameraX.LensFacing.FRONT, was testing on an emulator

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: meter.meter, PID: 15289
    java.lang.RuntimeException: Unable to start activity ComponentInfo{meter.meter/meter.meter.CameraActivity}: java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1
        at androidx.camera.core.Preview.onSuggestedResolutionUpdated(Preview.java:310)
        at androidx.camera.core.UseCase.updateSuggestedResolution(UseCase.java:375)
        at androidx.camera.core.CameraX.calculateSuggestedResolutions(CameraX.java:458)
        at androidx.camera.core.CameraX.bindToLifecycle(CameraX.java:144)
        at meter.meter.CameraActivity.onCreate(CameraActivity.java:68)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)

Code:

PreviewConfig config = new PreviewConfig.Builder().setLensFacing(CameraX.LensFacing.FRONT).build();

    Preview preview = new Preview(config);

    TextureView textureView = findViewById(R.id.textureView);


    preview.setOnPreviewOutputUpdateListener(new Preview.OnPreviewOutputUpdateListener() {

                     @Override
                     public void onUpdated(Preview.PreviewOutput output) {
                            textureView.setSurfaceTexture(output.getSurfaceTexture());
                        }
                    });

                    ImageCaptureConfig imageCaptureConfig = new ImageCaptureConfig.Builder().build();

                    imageCapture = new ImageCapture(imageCaptureConfig);
                    CameraX.bindToLifecycle((LifecycleOwner) this,imageCapture, preview);
like image 551
VINNUSAURUS Avatar asked May 16 '19 02:05

VINNUSAURUS


4 Answers

You should call setLensFacing(..) for each Config of UseCase that you passed to CameraX.bindToLifecycle((LifecycleOwner) this, imageCapture, preview)

like image 112
horseLai Avatar answered Oct 25 '22 11:10

horseLai


PreviewConfig ImageCaptureConfig ImageAnalysisConfig All need to be added

setLensFacing(CameraX.LensFacing.FRONT)

This is how I set it up

like image 43
meipo Avatar answered Oct 25 '22 10:10

meipo


add setLensFacing(CameraX.LensFacing.FRONT) to ImageCaptureConfig should solve your problem

like image 33
nesto Avatar answered Oct 25 '22 11:10

nesto


As an addition to nestos answer, I had to add setLensFacing(CameraX.LensFacing.FRONT) to both ImageCaptureConfig and PreviewConfig to make this work.

like image 21
Anders Rosten Avatar answered Oct 25 '22 10:10

Anders Rosten