Redth / ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
MIT License
1.07k stars 703 forks source link

Doesn't work with Xamarin.Forms v2.3.1.114 #399

Closed calbert52 closed 8 years ago

calbert52 commented 8 years ago

Cannot get to work with Xamarin.Forms v2.3.1.114 using either ZXingScannerPage() or MobileBarcodeScanner() approaches. Get System.NullReferenceException after trying to create:

new ZXingScannerPage(null, null) or new MobileBarcodeScanner()

andressbarajas commented 8 years ago

I'm getting the same thing except I get the exception when I call the Scan() method

calbert52 commented 8 years ago

Correct, it was on the Scan() method

andressbarajas commented 8 years ago

I updated the package and still experience this. This seems to only happening on Android when calling the Scan(). It gives this error on Xamarin Studio: "Object reference not set to an instance of an object."

I am using a Galaxy S5 Samsung API 23

ddpascua commented 8 years ago

I had the same issue, but got it to work using the following line in my Android Project in MainActivity.cs in OnCreate:

ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);

andressbarajas commented 8 years ago

IT WORKS!! Thank you. Thank you. Thank you

Redth commented 8 years ago

Hey folks, glad you've got it sorted. It's a minor annoyance, but it is in the README and sample forms app, so when in doubt, always check how the sample does it!

calbert52 commented 8 years ago

I am pretty sure that I followed the same coding pattern as in the sample forms project, but I still get the same error.

Android MainActivity code in OnCreate global::ZXing.Net.Mobile.Forms.Android.Platform.Init();

Included: public override void OnRequestPermissionsResult(....) { global::ZXing.Net.Mobile.Forms.Android.PermissionsHandler.OnRequestPermissionsResult( requestCode, permissions, grantResults); }

I have a custom ViewCell that creates a Entry control and a Button to click to scan a barcode. When I click on the button that executes the below code, I still get the following exception "Object reference not set to an instance of an object", when I execute scanner.Scan();

var scanner = new MobileBarcodeScanner(); scanner.TopText = "Top text"; scanner.BottomText ="Bottom text"; var result = await scanner.Scan();

kaitlynbrown commented 6 years ago

Nowhere in the readme does it mention that you need to call ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);