Open Magnabatt opened 6 years ago
I am also facing the similar crash when I try to open the scan page. I noticed that it is happening once I upgraded to Xamarin.forms 2.5.0.* version.
[ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.NullPointerException: Attemptinvoke virtual method 'android.content.res.Resources android.content.Context.getResources()' oa null objecreference
aSystem.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] i
I am getting the same issue
Any update on this? We can't move back to Xamarin.forms 2.4 and QR code scanning is not working for with Xamarin.forms 2.5.
I have having the same issue: VS 15.7.3, Xamarin Forms 3.0.0.530983, ZXing 2.4.1
Has anyone solved this?
Hi All,
Sorry for the delay. I have managed to get this working by updating my on click action to the below;
//Open QR scanner for code scanning
private async void BtnScanQR_Clicked(object sender, EventArgs e)
{
try
{
var options = new MobileBarcodeScanningOptions
{
AutoRotate = false,
UseFrontCameraIfAvailable = false,
TryHarder = true
};
var overlay = new ZXingDefaultOverlay
{
TopText = "Please scan QR code",
BottomText = "Align the QR code within the frame"
};
var QRScanner = new ZXingScannerPage(options,overlay);
await Navigation.PushModalAsync(QRScanner);
QRScanner.OnScanResult += (result) =>
{
// Stop scanning
QRScanner.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(() =>
{
Navigation.PopModalAsync(true);
strAccessToken.Text = result.Text.ToUpper().Trim();
//DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
}
catch (Exception ex)
{
GlobalScript.SeptemberDebugMessages("ERROR", "BtnScanQR_Clicked", "Opening ZXing Failed: " + ex);
}
}
Hope this works for you. Also if you find any improvements in the above please share with me.
Packages: Xamarin.Forms 2.5.1.52743 ZXing.Net.Mobile.Forms 2.3.2
@knight1219
if you used mvvmcross 6 ?? add this code at MainActivity Xamarin.Forms.Forms.Init(this, bundle);
@suyana That actually worked! I was facing this error for a while, so thank you very much :)
@suyana thank you! it helps me too!
ZXing.Net.Mobile.Forms.Android.Platform.Init(); Did not work for me. the newest version to date (12/31/2018) v2.4.1 still crashes. MobileBarcodeScanner.Initialize(Application); works adding to MainActivity.cs
ZXing.Net.Mobile: 2.4.1 ZXing.Net.Mobile.Forms: 2.4.1 Xamarin.Form: 3.4.0.1008975 Xamarin.Android.xxx: 28.0.0
I got the same issue. Please can you fix this critical issue!
UNHANDLED EXCEPTION:
Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue args) [0x00089] in
ZXing.Net.Mobile: 2.4.1 ZXing.Net.Mobile.Forms: 2.4.1 Xamarin.Forms: 3.5.0.129452 Xamarin.Android.Support.Annotations: 28.0.0.1 Xamarin.Android.Support.Compat: 28.0.0.1 Xamarin.Android.Support.Core.UI: 28.0.0.1 Xamarin.Android.Support.Design: 28.0.0.1 Xamarin.Android.Support.Fragment: 28.0.0.1 Xamarin.Android.Support.Media.Compat: 28.0.0.1 Xamarin.Android.Support.v4: 28.0.0.1 Xamarin.Android.Support.v7.AppCompat: 28.0.0.1 Xamarin.Android.Support.v7.CardView: 28.0.0.1 Xamarin.Android.Support.v7.MediaRouter: 28.0.0.1 Xamarin.Android.Support.v7.RecyclerView: 28.0.0.1
Using @Maxallica commit I was able to fix this issue. I created a ViewRenderer (using the code that is referenced in his fork) in my android project that replaced the one in the library and now the issue is gone. Thanks for the fix @Maxallica !
@suyana thank you! it helps me too!
Hi All, I feel this might be a double up but i have not been able to find a solution for the below error. Please let me know if a solution has been found?
I have recently updated VS to 15.6.7 and subsequently updated to Xamrin.Forms 2.5.1.444934 with Zxing.Net.Mobile 2.4.1 using .NETStandard 2.0. Since doing this I now get a null reference error each time I call the script.
Also I have only seen the error on Android (testing iOS tonight)
Here is the error:
In my MainActivity.cs I call the following after my Forms.Int:
//QR code reader
global::ZXing.Net.Mobile.Forms.Android.Platform.Init();
And this is the script with in my click event on the MainPage.cs:
//Open QR scanner for code scanning
private async void BtnScanQR_Clicked(object sender, EventArgs e)
{
try
{
var scanner = new MobileBarcodeScanner();
var result = await scanner.Scan();
strAccessToken.Text = result.Text.Trim();
}
catch (Exception ex)
{
GlobalScript.DebugMessages("ERROR", "BtnScanQR_Clicked", "Opening ZXing Failed: " + ex);
}
}
Even rolling back to my original versions of each package I'm now still having the same error.
Any assistance would be appretiated