Hi Guys,
And here's yet another question on Zxing's barcode scanner. I can't get it to work for days now, it's driving me insane. My app is very small and basic, but still not working. When launched there's only "SCAN" button and textbox for result. When "SCAN" is clicked, I'm always getting errors at line:
scanPage = new ZXingScannerPage();
And here's complete code run on button click event:
`ZXingScannerPage scanPage;
private async void btnScan_Clicked(object sender, EventArgs e)
{
try
{
scanPage = new ZXingScannerPage();
scanPage.AutoFocus();
scanPage.OnScanResult += (result) =>
{
// Stop scanning
scanPage.IsScanning = false;
scanPage.AutoFocus(0, 500);
// Pop the page and show the result
Device.BeginInvokeOnMainThread(() =>
{
Navigation.PopModalAsync();
//DisplayAlert("Scanned Barcode", result.Text, "OK");
txtBarcode.Text = result.Text;
});
};
await Navigation.PushModalAsync(scanPage);
}
catch (Exception ex)
{
throw;
}
}`
In detail the exception reads "Value cannot be null..". So I thought maybe it's because I pass nothing to ZXingScannerPage contructor and put some code for customOverlay. Unfortunately it still crashes at scanPage = new ZXingScannerPage(customOverlay: customOverlay);
, again with error "Value cannot be null..":
private async void btnScan_Clicked(object sender, EventArgs e)
{
try
{
var customOverlay = new StackLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
var torch = new Button
{
Text = "Toggle Torch"
};
torch.Clicked += delegate
{
scanPage.ToggleTorch();
};
customOverlay.Children.Add(torch);
//Pass in the custom overlay
scanPage = new ZXingScannerPage(customOverlay: customOverlay);
I'm going nuts, I did everything as in examples on net (tried several of them, all fail at some point). The one above is example from official ZXing's component site but still without success (and this is trivial app so far).
I'd attach whole solution for everyone to see, but it's around 100 MB (?) so I can attach individual files if you'd like to have a look.
Your help is much appreciated!
Robert