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
373 stars 430 forks source link

CRASH java.lang.NullPointerException: Attempt to invoke interface method 'void #91

Open Xgamefactory opened 4 years ago

Xgamefactory commented 4 years ago
java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.EventChannel$EventSink.success(java.lang.Object)' on a null object reference
E/AndroidRuntime(32669):    at com.amolg.flutterbarcodescanner.FlutterBarcodeScannerPlugin$1.run(FlutterBarcodeScannerPlugin.java:201)
E/AndroidRuntime(32669):    at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime(32669):    at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime(32669):    at android.os.Looper.loop(Looper.java:237)
E/AndroidRuntime(32669):    at android.app.ActivityThread.main(ActivityThread.java:7857)
E/AndroidRuntime(32669):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(32669):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(32669):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
I/Process (32669): Sending signal. PID: 32669 SIG: 9
Lost connection to device.

what i try to do is stream barcodes and get only qrcode not standart ean carcodes.

String res = await FlutterBarcodeScanner.getBarcodeStreamReceiver(
            "#ff6666", "Cancel", true, ScanMode.QR)
        .firstWhere((code) {
      print("singleWhere $code");
      if (code.toString().startsWith("http")) {
        print("founded");
        return true;
      }
      return false;
    });

using latest version 1.0

prokons commented 4 years ago

I have same problem with example code:

Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference

Actually qrcode value is read into barcodeScanRes but then app crashes

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

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

Using latest version 1.0

Android studio 3.6.3 Runtime version 1.8.0_212 Flutter version 1.12.13+hotfix.9 Emulator Pixel2, API 23

Xgamefactory commented 4 years ago

yes latest plugin causes crash. we are switching back to barcode_scan plugin.

prokons commented 4 years ago

Unfortunately also barcode_scan is not working for me https://github.com/mintware-de/flutter_barcode_reader/issues/226#issuecomment-623088525

AmolGangadhare commented 4 years ago

@Xgamefactory @prokons

Can you provide a sample barcode so I can reproduce this issue?

prokons commented 4 years ago

At last I managed to make barcode_scan running and I used it. Anyway. as a sample, I just used an online generated qrCode with my name.

vglider commented 4 years ago

i have same problem and it happened using your example as test ( i use flutter). the only way to not making crash the app is the streaming barcode , it gets the code but i have to navigate back to my page....there is another way to make it work?

vglider commented 4 years ago

i tried to recreate by my self getBarcodeStreamReceiver closing at the first code got. when: "isContinuousScan": true,

evreything is ok, when i try to change it in : "isContinuousScan": false,

it crashes

vglider commented 4 years ago

i've just tried using .single or .first instead of .listen but it doesn't quit cam. i need to close at first element. and any way i try it doesn't work. i need it soon as possible

AmolGangadhare commented 4 years ago

@vglider Allow me some time to reproduce this issue at my end.

Meanwhile, can you provide me some details like which device on which you are facing the issue?

vglider commented 4 years ago

@vglider Allow me some time to reproduce this issue at my end.

Meanwhile, can you provide me some details like which device on which you are facing the issue?

package version 1.0.1

Android Studio 4.0 Build #AI-193.6911.18.40.6514223, built on May 20, 2020 Runtime version: 1.8.0_242-release-1644-b01 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0 Huawei MediaPad T5 API from 26 to 29 (Android 8.0 to 10.0)

if you need further details just ask

vglider commented 4 years ago

i build my widget with GestureDetector, wich my onTap function is:

import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart' as scanner;

function: () { scanner.FlutterBarcodeScanner.getBarcodeStreamReceiver( "#000000", "Cancel", false, scanner.ScanMode.DEFAULT, ).listen( (code) { userQR = code; print(userQR); }, ); },

vglider commented 4 years ago

i tried with another device but stil the same... i used Alcatel 1S (Android 9.0)

vglider commented 4 years ago

@AmolGangadhare have you replicated the issue?

rymesaint commented 4 years ago

i got this issue too

vglider commented 4 years ago

@AmolGangadhare hi, i just upgrade my flutter version (now is: 1.17.3) and normal scan works...thanks

AmolGangadhare commented 3 years ago

Please check with v 2.0.0 if the issue still there. Potential fix has been made.