RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 405 forks source link

java.lang.NullPointerException Exception on Some Devices #162

Closed itt80 closed 6 years ago

itt80 commented 6 years ago

It's working perfectly. But I get these exceptions on some devices

Fotoapparat
                .with(this)
                //.cameraProvider(CameraProviders.v2(this)) // change this to v2 to test Camera2 API
                .into(cameraView)
                .previewScaleType(ScaleType.CENTER_CROP)
                .photoSize(wideRatio(smallestSize()))
                .lensPosition(lensPosition(position))
                .focusMode(firstAvailable(
                        continuousFocus(),
                        autoFocus(),
                        fixed()
                ))
                .previewFpsRange(rangeWithHighestFps())
                .sensorSensitivity(highestSensorSensitivity())
                .frameProcessor(new SampleFrameProcessor())
                .logger(loggers(
                        logcat(),
                        fileLogger(this)
                ))
                .cameraErrorCallback(new CameraErrorCallback() {
                    @Override
                    public void onError(CameraException e) {
                        Toast.makeText(FotoApparatActivity.this, e.toString(), Toast.LENGTH_LONG).show();
                    }
                })
                .build();

It's occured this exception messages;

java.lang.NullPointerException
Attempt to invoke virtual method 'float io.fotoapparat.parameter.Size.getAspectRatio()' on a null object reference

io.fotoapparat.parameter.provider.InitialParametersProvider.previewWithSameAspectRatio (InitialParametersProvider.java:70)
io.fotoapparat.parameter.provider.InitialParametersProvider.validPreviewSizeSelector (InitialParametersProvider.java:61)
io.fotoapparat.parameter.provider.InitialParametersProvider.previewSizeParameters (InitialParametersProvider.java:114)
io.fotoapparat.parameter.provider.InitialParametersProvider.initialParameters (InitialParametersProvider.java:84)
io.fotoapparat.routine.StartCameraRoutine.tryToStartCamera (StartCameraRoutine.java:60)
io.fotoapparat.routine.StartCameraRoutine.run (StartCameraRoutine.java:47)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587)
java.lang.Thread.run (Thread.java:818)

Library: 1.5.0

Devices and Android Api:

itt80 commented 6 years ago

Why are the device models working stable? Are they unsupported?

Diolor commented 6 years ago

You only select a wide ratio ( wideRatio(smallestSize()) ) so I assume these devices cannot generate a aspect ratio. Therefore the exception. use firstAvailable() selector or catch the error on these devices