Alex-Dobrynin/Controls.UserDialogs.Maui

NUll reference exception in Android

randomroxks opened this issue · 6 comments

I followed the instructions as mentioned in the readme. The IOS portion works fine, but the Android throws exception.
All I'm doing is to call

UserDialogs.Instance.ShowLoading();
it throws the following exception.

Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 20830 at Java.Interop.JniPeerMembers.JniInstanceMethods.FinishCreateInstance(String constructorSignature, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:line 174 at Android.App.Dialog..ctor(Context context) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.App.Dialog.cs:line 142 at AndroidHUD.AndHUD.<>c__DisplayClass28_0.<SetupDialog>b__0(Object state) at Android.App.SyncContext.Send(SendOrPostCallback d, Object state) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:line 46 at AndroidHUD.AndHUD.SetupDialog(Context context, MaskType maskType, Action cancelCallback, Func4 customSetup, Action1 prepareDialogCallback, Action1 dialogShownCallback)
at AndroidHUD.AndHUD.showStatus(Context context, Boolean spinner, String status, MaskType maskType, Nullable1 timeout, Action clickCallback, Boolean centered, Action cancelCallback, Action1 prepareDialogCallback, Action1 dialogShownCallback) at AndroidHUD.AndHUD.Show(Context context, String status, Int32 progress, MaskType maskType, Nullable1 timeout, Action clickCallback, Boolean centered, Action cancelCallback, Action1 prepareDialogCallback, Action1 dialogShownCallback)
at Controls.UserDialogs.Maui.HudDialog.Show()
at Controls.UserDialogs.Maui.HudDialog.Update(HudDialogConfig config)
at Controls.UserDialogs.Maui.UserDialogsImplementation.CreateHudInstance(HudDialogConfig config)
at Controls.UserDialogs.Maui.UserDialogsImplementation.CreateOrUpdateHud(HudDialogConfig config)
at Controls.UserDialogs.Maui.UserDialogsImplementation.Loading(String message, String cancelText, Boolean show, Nullable1 maskType, Action cancel) at Controls.UserDialogs.Maui.UserDialogsImplementation.ShowLoading(String message, Nullable1 maskType)
`

@randomroxks Hi! Did you try to run sample project, is there the same issue? If not, download repo and run sample, please, and give feedback

yes just did. I ran the sample project. I removed the project reference and added the nuget package but it seems to work there.
So I'm not sure what is the issue here. May the only thing that is different is, I have a shared library and about 5 different apps that feed off that library. I added the nuget to both shared library project and the app projects, but the issue persists.
I also copied the csproj content to my project, the issue still exists.

May be I'm calling it too soon.

@randomroxks do you use maui in your apps? did you register dependencies as in readme? when do you call it?

Yes, this is a maui app. I call the .Instance.ShowLoading() after the MauiApp creation is complete.
`
UseUserDialogs(true, () =>
{
#if ANDROID
var fontFamily = "RNSSanz-Normal.otf";
#else
var fontFamily = "RNSSanz-Normal";
#endif
AlertConfig.DefaultMessageFontFamily = fontFamily;
AlertConfig.DefaultUserInterfaceStyle = UserInterfaceStyle.Dark;
AlertConfig.DefaultPositiveButtonTextColor = Colors.Purple;
ConfirmConfig.DefaultMessageFontFamily = fontFamily;
ActionSheetConfig.DefaultMessageFontFamily = fontFamily;
ToastConfig.DefaultMessageFontFamily = fontFamily;
SnackbarConfig.DefaultMessageFontFamily = fontFamily;
HudDialogConfig.DefaultMessageFontFamily = fontFamily;
}).UseMauiCommunityToolkit();

`

after the MauiApp creation is complete.

this is when? in same file or what? can you show it?

Ok, i think I figured it out. The first issue of the readme send me in the right direction. The property change for isBusy was firing before the page was getting displayed. My bad. Thanks for sending me in the right direction.