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
380 stars 499 forks source link

invoke 'getPackageName()' on a null object reference #174

Open gwaelesadeo opened 3 years ago

gwaelesadeo commented 3 years ago

Describe the bug Hello, In my app, the FlutterBarcodeScanner.scanBarcode method is called when the user tap on a FAB. On a fresh install, the scanner screen is not displayed and I've got this message in the logs: E/FlutterBarcodeScannerPlugin(15813): startView: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference I can tap several times on the FAB, I've got the same message each time. If I quit the app and relaunch it, all works fine, the scanner screen is displayed as expected. If I remove the app and reinstall it, I've got the bug again, only on the first launch just after the fresh install.

To Reproduce Steps to reproduce the behavior:

  1. (Re)install the app
  2. Click on a FAB
  3. See error

Expected behavior I would the scanner library works on the first use just after a fresh install.

Smartphone (please complete the following information):

Additional context The library is really easy to use (thanks for that)

gwaelesadeo commented 3 years ago

Hello, I have added some logs in the plugin, into the file FlutterBarcodeScannerPlugin.java. This is the result : On fresh install (the boolean is the result of the test activity != null) E/FlutterBarcodeScannerPlugin( 9029): [GWA]: FlutterBarcodeScannerPlugin E/FlutterBarcodeScannerPlugin( 9029): [GWA]: onAttachedToActivity (true) E/FlutterBarcodeScannerPlugin( 9029): [GWA]: createPluginSetup (true) E/FlutterBarcodeScannerPlugin( 9029): [GWA]: FlutterBarcodeScannerPlugin E/FlutterBarcodeScannerPlugin( 9029): [GWA]: onAttachedToActivity (true) E/FlutterBarcodeScannerPlugin( 9029): [GWA]: createPluginSetup (true) E/FlutterBarcodeScannerPlugin( 9029): [GWA]: clearPluginSetup E/FlutterBarcodeScannerPlugin( 9029): [GWA]: startBarcodeScannerActivityView (false)

After restart : E/FlutterBarcodeScannerPlugin( 9245): [GWA]: FlutterBarcodeScannerPlugin E/FlutterBarcodeScannerPlugin( 9245): [GWA]: onAttachedToActivity (true) E/FlutterBarcodeScannerPlugin( 9245): [GWA]: createPluginSetup (true) E/FlutterBarcodeScannerPlugin( 9245): [GWA]: startBarcodeScannerActivityView (true)

I don't know why the activity is restarted. That should come from another plugin or my code. I will continue to investigate but if someone have an idea to help me he's welcome :) Thx