I am using the ZXing.Net.Mobile
NuGet package for scanning barcode numbers. I have done everything as per this blog.
My Code
//Main Project Interface
public interface IQrScanningService
{
Task<string> ScanAsync();
}
//Android part implementation
[assembly: Dependency(typeof(XFBarcode.Droid.Services.QrScanningService))]
namespace projectname.Droid.Services
{
public class QrScanningService : IQrScanningService
{
public async Task<string> ScanAsync()
{
var optionsDefault = new MobileBarcodeScanningOptions();
var optionsCustom = new MobileBarcodeScanningOptions();
var scanner = new MobileBarcodeScanner()
{
TopText = "Scan the QR Code",
BottomText = "Please Wait",
};
var scanResult = await scanner.Scan(optionsCustom);
return scanResult.Text;
}
}
}
But when I execute I am getting System.NullReferenceException: 'Object reference not set to an instance of an object.'
. What else I am missing here? I saw a similar thread here but don't how to download use a package from GitHub.
You missed the initialization step.
Try this:
in your MainActivity :
You also could initialize in MainActivity
OnCreate()
method directly.