【发布时间】:2019-11-20 14:45:13
【问题描述】:
zxing QR 码阅读器导致崩溃 Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on an null object reference' 下面是我添加的代码。
{
try
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
catch (Exception)
{
return;
}
}
// and
try
{
ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
}
catch (Exception)
{
return;
}
// on the on create
// button click
private async void Button_Clicked(object sender, EventArgs e)
{
try
{
_scanPage = new ZXingScannerPage();
if (_scanPage != null)
{
_scanPage.OnScanResult += (result) =>
{
_scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(() =>
{
Navigation.PopAsync();
DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
}
await Navigation.PushAsync(_scanPage).ConfigureAwait(true);
}
catch (Exception)
{
return;
}
}
插件详情如下
ZXing.Net.Mobile 2.4.1 和 ZXing.Net.Mobile.Forms 2.4.1
请建议我是否有任何其他插件可以代替我们使用
【问题讨论】:
-
您是否尝试在 OnAppearing 上设置 IsScanning 为真?
-
@sermet 是的,我也添加了。我在 xaml 中添加并将 isScaning 设置为 true 仍然遇到同样的问题。如您所见,我也以其他方式添加了代码。在按钮上单击我已经创建了新实例
-
@sermet 这是 Xaml 中的代码
-
我已经创建了一个新的解决方案并尝试实现它。它工作正常。我的解决方案可能是什么问题。我正在使用 mvvmcross Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on an null object reference'
标签: xamarin.forms zxing barcode-scanner