AmolGangadhare / flutter_barcode_scanner

Barcode scanner plugin for flutter. Supports barcode scanning for Android and iOS
https://pub.dev/packages/flutter_barcode_scanner
MIT License
379 stars 455 forks source link

App close after scanning barcode #69

Closed bontew closed 3 years ago

bontew commented 4 years ago

Describe the bug I got error while scanning barcode. Barcode value is shown in dart log, but app is stopped. I dont know i wrong in implementation or that's a bug.

Smartphone (please complete the following information):

Log

> FATAL EXCEPTION: main
    Process: com.mozdev.barcode_scan, PID: 15566
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9001, result=0, data=Intent { (has extras) }} to activity {com.mozdev.barcode_scan/com.mozdev.barcode_scan.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4382)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4424)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
        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:1818)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6762)
        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.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference
        at com.amolg.flutterbarcodescanner.FlutterBarcodeScannerPlugin.onActivityResult(FlutterBarcodeScannerPlugin.java:157)
        at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEnginePluginRegistry.java:634)
        at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onActivityResult(FlutterEnginePluginRegistry.java:367)
        at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:546)
        at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:594)
        at android.app.Activity.dispatchActivityResult(Activity.java:7454)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4375)

Code

Future<void> scanBarcodeNormal(BuildContext context) async {
    String barcodeScanRes;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
          "#ff6666", "Cancel", true, ScanMode.BARCODE);
      print(barcodeScanRes);
    } on PlatformException {
      barcodeScanRes = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _scanBarcode = barcodeScanRes;
    });
}

**Dart/Flutter Log**
> I/flutter (17677): 8999909000711

**Depedencies**
pubspec.yaml

flutter_barcode_scanner:
    git:
      url: git://github.com/AmolGangadhare/flutter_barcode_scanner.git
bverhagen commented 4 years ago

I have exactly the same issue on a HTC U11, also with Android 9.

I observed that, when I restart the application after the crash, it prints the QR code it was scanning just before the crash. So it seems the detection actually works. The behaviour is the same in debug and release mode.

zigang93 commented 4 years ago

Happened on pixel 2 phone also.. any quick fix?

whizgenius1 commented 4 years ago

Happened to my galaxy s8 too, app closes after scam

Elvino12 commented 4 years ago

I face the same issues, cold someone give a quick solution

davehutchy commented 4 years ago

I have the same issue also

atheros commented 4 years ago

For me, the git version doesn't work at all, successful scanning is crashing the app with same trace as @bontew provided. Same with pressing cancel.

Cannot use release version if this plugin because it doesn't work with latest flutter :(

AmolGangadhare commented 4 years ago

V1.0.0 has been released, can you try it on the latest and confirm the same?

AmolGangadhare commented 4 years ago

If possible can anyone provide a sample barcode on which this crash happens?

rahmanrezaee commented 4 years ago

If possible can anyone provide a sample barcode on which this crash happens?

i use V1.0.1 but not work

navaneeth-algorithm commented 3 years ago
 Process: com.example.barcode_label, PID: 18798
E/AndroidRuntime(18798): java.lang.RuntimeException: Unable to destroy activity {com.example.barcode_label/com.amolg.flutterbarcodescanner.BarcodeCaptureActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference
E/AndroidRuntime(18798):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3919)
E/AndroidRuntime(18798):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3937)
E/AndroidRuntime(18798):    at android.app.ActivityThread.access$1600(ActivityThread.java:166)
E/AndroidRuntime(18798):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1453)
E/AndroidRuntime(18798):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(18798):    at android.os.Looper.loop(Looper.java:148)
E/AndroidRuntime(18798):    at android.app.ActivityThread.main(ActivityThread.java:5541)
E/AndroidRuntime(18798):    at java.lang.reflect.Method.invoke(Native Method)

E/AndroidRuntime(18798):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
E/AndroidRuntime(18798):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
E/AndroidRuntime(18798): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference
E/AndroidRuntime(18798):    at com.amolg.flutterbarcodescanner.camera.CameraSource$FrameProcessingRunnable.release(CameraSource.java:967)
E/AndroidRuntime(18798):    at com.amolg.flutterbarcodescanner.camera.CameraSource.release(CameraSource.java:273)
E/AndroidRuntime(18798):    at com.amolg.flutterbarcodescanner.camera.CameraSourcePreview.release(CameraSourcePreview.java:84)
E/AndroidRuntime(18798):    at com.amolg.flutterbarcodescanner.BarcodeCaptureActivity.onDestroy(BarcodeCaptureActivity.java:266)
E/AndroidRuntime(18798):    at android.app.Activity.performDestroy(Activity.java:6479)
E/AndroidRuntime(18798):    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1149)
E/AndroidRuntime(18798):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3906)
E/AndroidRuntime(18798):    ... 9 more
I/Process (18798): Sending signal. PID: 18798 SIG: 9
Lost connection to device.
navaneeth-algorithm commented 3 years ago

Crashes after scanning

AmolGangadhare commented 3 years ago

The potential fix has been made. It will be available in the upcoming release. Please refer #137

AmolGangadhare commented 3 years ago

The issue has been fixed in V 2.0.0.

Closing this as of now, feel free to open a new issue.