2
votes

I am trying to implement ZXing.Net.Mobile on for Android and having a runtime error.

        MobileBarcodeScanner scanner = new MobileBarcodeScanner(_activity);
        ZXing.Result result = await scanner.Scan(); // crashes here
        HandleZXingResult(result);

I use Xamarin for Visual Studio.

The issue seems to be about missing Resources and when it tries to SetContentView(layout). I am just using the ZXing Dlls. Not sure where to include the resources.

Stack Trace:

06-16 01:03:44.353 I/MonoDroid( 7783): UNHANDLED EXCEPTION:
06-16 01:03:44.413 I/MonoDroid( 7783): Android.Content.Res.Resources+NotFoundException: Exception of type 'Android.Content.Res.Resources+NotFoundException' was thrown.
06-16 01:03:44.413 I/MonoDroid( 7783): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () 
06-16 01:03:44.413 I/MonoDroid( 7783): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:896
06-16 01:03:44.413 I/MonoDroid( 7783): at Android.App.Activity.SetContentView (int) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:3244
android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/icon.png from xml type layout resource ID #0x7f020000
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:3733)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:3680)
    at android.content.res.Resources.getLayout(Resources.java:2166)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:366)
    at android.app.Activity.setContentView(Activity.java:2031)
    at zxing.mobile.ZxingActivity.n_onCreate(Native Method)
    at zxing.mobile.ZxingActivity.onCreate(ZxingActivity.java:31)
    at android.app.Activity.performCreate(Activity.java:5451)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
    at android.app
2

2 Answers

0
votes

Don't use nuget for android, Try to install components from Xamarin Component Store. It worked for me.

0
votes

I had this issue because the zxing nuget package was referenced in a dependency assembly (our own barcode plugin assembly abstraction), but not in the parent app assembly. Referenced the package in both projects, and then it ran fine.