FlutterAndroid技术分享

Flutter plugin:camera android.vi

2020-07-11  本文已影响0人  Air_w

使用flutter-plugin-camera时在“部分手机”上出现下述问题

日志


java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Surface android.media.ImageReader.getSurface()' on a null object reference

日志


E/AndroidRuntime(27582): java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Surface android.media.ImageReader.getSurface()' on a null object reference
E/AndroidRuntime(27582):    at io.flutter.plugins.camera.Camera.startPreview(:424)
E/AndroidRuntime(27582):    at io.flutter.plugins.camera.Camera$2.onOpened(:160)
E/AndroidRuntime(27582):    at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:148)
E/AndroidRuntime(27582):    at android.os.Handler.handleCallback(Handler.java:900)
E/AndroidRuntime(27582):    at android.os.Handler.dispatchMessage(Handler.java:103)
E/AndroidRuntime(27582):    at android.os.Looper.loop(Looper.java:219)
E/AndroidRuntime(27582):    at android.app.ActivityThread.main(ActivityThread.java:8347)
E/AndroidRuntime(27582):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27582):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
E/AndroidRuntime(27582):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)

解决方案

在startPreview时,加入下方的校验代码


if (pictureImageReader == null || pictureImageReader.getSurface() == null) {
            return;
        }

上一篇下一篇

猜你喜欢

热点阅读