我正在尝试使用 firebase ml vision 从图像中读取文本,并使用 image_picker 从图库中获取图像。
图像选择器:^0.6.1+4
firebase_ml_vision:^0.9.2+1
获取图像
File imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
应用程序仅在执行以下代码的最后一行时才会崩溃
final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(imageFile);
final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
final VisionText visionText = await textRecognizer.processImage(visionImage);
//crash the app when execution above line
错误信息
W/ExifInterface(15273): Skip the tag entry since data format (ULONG) is unexpected for tag: LightSource
W/ExifInterface(15273): Stop reading file since a wrong offset may cause an infinite loop: 0
W/ExifInterface(15273): Stop reading file since a wrong offset may cause an infinite loop: 0
W/ExifInterface(15273): Skip the tag entry since data format (ULONG) is unexpected for tag: LightSource
W/ExifInterface(15273): Stop reading file since a wrong offset may cause an infinite loop: 0
W/ExifInterface(15273): Stop reading file since a wrong offset may cause an infinite loop: 0
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at io.flutter.plugins.firebasemlvision.FirebaseMlVisionPlugin.getDetector(FirebaseMlVisionPlugin.java:205)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at io.flutter.plugins.firebasemlvision.FirebaseMlVisionPlugin.handleDetection(FirebaseMlVisionPlugin.java:74)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at io.flutter.plugins.firebasemlvision.FirebaseMlVisionPlugin.onMethodCall(FirebaseMlVisionPlugin.java:49)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/firebase_ml_vision(15273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter (15273): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null)
E/flutter (15273): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (15273): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter (15273): <asynchronous suspension>
E/flutter (15273): #2 TextRecognizer.processImage (package:firebase_ml_vision/src/text_recognizer.dart:22:38)
E/flutter (15273): <asynchronous suspension>
E/flutter (15273): #3 _ScanState._initializeVision (package:scanner/ui/scan.dart:65:56)
E/flutter (15273): <asynchronous suspension>
E/flutter (15273): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
E/flutter (15273): #5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:729:32)
E/flutter (15273): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (15273): #7 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (15273): #8 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter (15273): #9 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter (15273): #10 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter (15273): #11 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter (15273): #12 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (15273): #13 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (15273): #14 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (15273): #15 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (15273): #16 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (15273): #17 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (15273): #18 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (15273): #19 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (15273): #20 _invoke1 (dart:ui/hooks.dart:263:10)
E/flutter (15273): #21 _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5)
我该如何解决?