khjde1207 / tesseract_ocr

Tesseract OCR for flutter
BSD 3-Clause "New" or "Revised" License
62 stars 31 forks source link

I had this problem when I called the menthod again, the first call was successful #15

Closed xuuanthuc closed 2 years ago

xuuanthuc commented 2 years ago

My Code: textScanController.text = await FlutterTesseractOcr.extractText(_homeController.filePath.value, language: 'eng');

E/MethodChannel#flutter_tesseract_ocr(31435): Failed to handle method call
E/MethodChannel#flutter_tesseract_ocr(31435): java.lang.IllegalStateException
E/MethodChannel#flutter_tesseract_ocr(31435):   at com.googlecode.tesseract.android.TessBaseAPI.setPageSegMode(TessBaseAPI.java:547)
E/MethodChannel#flutter_tesseract_ocr(31435):   at io.paratoner.flutter_tesseract_ocr.FlutterTesseractOcrPlugin.onMethodCall(FlutterTesseractOcrPlugin.java:58)
E/MethodChannel#flutter_tesseract_ocr(31435):   at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#flutter_tesseract_ocr(31435):   at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#flutter_tesseract_ocr(31435):   at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/MethodChannel#flutter_tesseract_ocr(31435):   at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter_tesseract_ocr(31435):   at android.os.MessageQueue.next(MessageQueue.java:330)
E/MethodChannel#flutter_tesseract_ocr(31435):   at android.os.Looper.loop(Looper.java:169)
E/MethodChannel#flutter_tesseract_ocr(31435):   at android.app.ActivityThread.main(ActivityThread.java:7143)
E/MethodChannel#flutter_tesseract_ocr(31435):   at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_tesseract_ocr(31435):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
E/MethodChannel#flutter_tesseract_ocr(31435):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
I/flutter (31435): PlatformException(error, null, null, java.lang.IllegalStateException
I/flutter (31435):  at com.googlecode.tesseract.android.TessBaseAPI.setPageSegMode(TessBaseAPI.java:547)
I/flutter (31435):  at io.paratoner.flutter_tesseract_ocr.FlutterTesseractOcrPlugin.onMethodCall(FlutterTesseractOcrPlugin.java:58)
I/flutter (31435):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
I/flutter (31435):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
I/flutter (31435):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
I/flutter (31435):  at android.os.MessageQueue.nativePollOnce(Native Method)
I/flutter (31435):  at android.os.MessageQueue.next(MessageQueue.java:330)
I/flutter (31435):  at android.os.Looper.loop(Looper.java:169)
I/flutter (31435):  at android.app.ActivityThread.main(ActivityThread.java:7143)
I/flutter (31435):  at java.lang.reflect.Method.invoke(Native Method)
I/flutter (31435):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
I/flutter (31435):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
I/flutter (31435): )
xuuanthuc commented 2 years ago

but when i restart the app the method works again

khjde1207 commented 2 years ago

Please check in the latest version. I think this part is the problem. https://github.com/khjde1207/tesseract_ocr/blob/0d2d22b2e5c544966c38a5d2567acb643b80e604/android/src/main/java/io/paratoner/flutter_tesseract_ocr/FlutterTesseractOcrPlugin.java#L100