Reputation: 3681
In my viewmdodel class, I am calling a function from constructor. Inside of that function I am using Userdialoges and displayalert properties. But both are not showing in UI. Getting exception for both.
Displayalert Exception :
Exception:>System.NullReferenceException: Object reference not set to an instance of an object.
UserDialogs Exception :
Exception:>System.ArgumentException: In android, you must call UserDialogs.Init(Activity) from your first activity OR UserDialogs.Init(App) from your custom application OR provide a factory function to get the current top activity via UserDialogs.Init(() => supply top activity)
I have also implemented the pull down to refresh option. When pull down I am calling the same function, but that call is not from the constructor. So when pull down UserDialoges and Displayalert are working.
My code:
UserDialogs.Instance.ShowLoading("Loading");
await Application.Current.MainPage.DisplayAlert("Alert", "No Internet Connection", "Ok");
So how can I activate the userdialoges and displayalert initially when calling the function from constructor?
Upvotes: 1
Views: 378
Reputation: 3681
Solved by comment the function call in constructor and inside of onappearing(), call the same function using the viewmodel class object(added in xaml.cs file not in viewmodel).
protected override async void OnAppearing()
{
dbvm.UserList(); //dbvm is viewmodel class object
}
Upvotes: 1