I am working on a mobile app using Xamarin Forms. To achieve the look I want, I have derived my theme from android:Theme.Material, as follows in the styles.xml file:
<style name="MainTheme" parent="android:Theme.Material">
...
</style>
This results in any call to the DisplayAlert method in the shared library throwing the following exception:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x0
I can reproduce this error reliably in a completely new project just by changing the theme parent to android:Theme.Material in styles.xml.
I have no idea how to solve this problem and have not been able to find anyone else who has had or solved this issue by searching. The exception suggests that there is a resource I need to add somewhere, but I have no idea what or to where.
Full stack trace below:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x0
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <26521a5118b44c858c385715922b9d5d>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <26521a5118b44c858c385715922b9d5d>:0
at Android.App.Dialog.Show () [0x0000a] in <d3b924763d4a465c85b26f6e8edc8a53>:0
at Xamarin.Forms.Platform.Android.PopupManager+PopupRequestHelper+FlexibleAlertDialog.Show () [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.Android\PopupManager.cs:496
at Xamarin.Forms.Platform.Android.PopupManager+PopupRequestHelper.OnAlertRequested (Xamarin.Forms.Page sender, Xamarin.Forms.Internals.AlertArguments arguments) [0x00111] in D:\a\1\s\Xamarin.Forms.Platform.Android\PopupManager.cs:152
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395
--- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281)
at android.content.res.Resources.getLayout(Resources.java:1175)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatDialog.setContentView(AppCompatDialog.java:95)
at androidx.appcompat.app.AlertController.installContent(AlertController.java:232)
at androidx.appcompat.app.AlertDialog.onCreate(AlertDialog.java:279)
at android.app.Dialog.dispatchOnCreate(Dialog.java:421)
at android.app.Dialog.show(Dialog.java:315)
at mono.java.lang.RunnableImplementor.n_run(Native Method)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
} Android.Content.Res.Resources.NotFoundException