We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Java.Lang.NullPointerException when show Popup.

Notify: Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference'

Source:
private static SfPopupLayout popupAlert;
 public static async Task DisplayAlert(string title, string message, string btnAccept)
        {
            if (popupAlert != null)
                popupAlert.IsOpen = false;
            popupAlert = new SfPopupLayout();
            if (string.IsNullOrEmpty(title))
                popupAlert.PopupView.ShowHeader = false;

            popupAlert.PopupView.PopupStyle.AcceptButtonTextColor = Color.FromHex("#3F51B5");

            popupAlert.StaysOpen = true;
            popupAlert.PopupView.ShowCloseButton = false;
            popupAlert.PopupView.AnimationMode = AnimationMode.None;
            popupAlert.PopupView.AutoSizeMode = AutoSizeMode.Height;
            popupAlert.PopupView.HeaderTitle = title;
            popupAlert.PopupView.AcceptButtonText = "    " + btnAccept + "    ";
            popupAlert.PopupView.ContentTemplate = ContentAlert(message);
            popupAlert.IsOpen = true;
            while (popupAlert.IsOpen)
            {
                await Task.Delay(100);
            }
        }

My issue:
- I call my method DisplayAlert when Load application. My Page.Content  is SfPopupLayout (X) , but when MainActivity call method LoadApplication(new App()), X has not been contructor. And X.Content has not been show. 
- And I have the error when using popupAlert.IsOpen = true; I need solution, And I think we need the Variable popupAlert.CanOpen...etc. I was tried Try Catch but it not working. 

Thanks you


6 Replies

NK Nguyen Khoa Lu December 28, 2019 01:03 AM UTC

Who can help me? Please


DB Deepika Balasubramaniyan Syncfusion Team December 30, 2019 02:07 PM UTC

Hi Nguyen Khoa Lu,

Thank you for contacting Syncfusion support.

We have checked reported issue “Java.Lang.NullPointerException when show Popup” with given settings, We are unable to replicate the issue from our side. As you instructed Popup settings added method named as “DisplayAlert has called when load application. When load the page, popup has open with out any crash as expected. For your reference we have attached the tested sample following here. If the sample doesn’t meet your requirement, kindly modify the sample based on your scenario and revert us back with replication procedure and with following details,it will be helpful for us to give you a better solution.


      1. SfPopupLayout Product version

2. Xamarin Forms version
3. Issue replicated Android device

Sample link:
https://www.syncfusion.com/downloads/support/forum/150197/ze/F1501971503577096.zip

Regards,
Deepika.





RU Rubén replied to Deepika Balasubramaniyan June 5, 2021 03:19 AM UTC

Hi Nguyen Khoa Lu,

Thank you for contacting Syncfusion support.

We have checked reported issue “Java.Lang.NullPointerException when show Popup” with given settings, We are unable to replicate the issue from our side. As you instructed Popup settings added method named as “DisplayAlert has called when load application. When load the page, popup has open with out any crash as expected. For your reference we have attached the tested sample following here. If the sample doesn’t meet your requirement, kindly modify the sample based on your scenario and revert us back with replication procedure and with following details,it will be helpful for us to give you a better solution.


      1. SfPopupLayout Product version

2. Xamarin Forms version
3. Issue replicated Android device

Sample link:
https://www.syncfusion.com/downloads/support/forum/150197/ze/F1501971503577096.zip

Regards,
Deepika.




hay alguna solucion al respecto?


PP Pradhap Palani Syncfusion Team June 7, 2021 01:16 PM UTC

Hi Nguyen Khoa Lu, 
 
Thank you for contacting Syncfusion support.  
 
Based on the provided call stack, you missed to initialize SfPopupLayoutRenderer in the Android project of your application. Please let me know whether you are facing mentioned call stack issue or any other issues? if you are facing the call stack issues, you must initialize the Popup renderer in the MainActivity.cs file as described in our UG documentation or the below code snippet. 
 
 
 
protected override void OnCreate(Bundle bundle) 
{ 
    ... 
    global::Xamarin.Forms.Forms.Init(this, bundle); 
    Syncfusion.XForms.Android.PopupLayout.SfPopupLayoutRenderer.Init(); 
           Or  
   // this refers to application context or Main Activity 
    Syncfusion.XForms.Android.PopupLayout.SfPopupLayoutRenderer.Init(this); 
    LoadApplication(new App()); 
} 
 
Please let us know if you need any further assistance 
 
Regards, 
Pradhap Palani 



RM Robert Manegene replied to Pradhap Palani August 12, 2021 06:57 PM UTC

Hi,

Expericnced similar issue in after upgrading xamarin forms to version 5.. and Android project to Android X.

Adding 

    Syncfusion.XForms.Android.PopupLayout.SfPopupLayoutRenderer.Init(this); 

in the Adnroid Mainactivity class fixed the problem


Regards,

Robert M



KK Karthikraja Kalaimani Syncfusion Team August 13, 2021 05:57 AM UTC

Hi Robert,

Thanks for the update. We glad to know that the previously provided solution has fix your problem. Please let us know if you need further assistance from us. 

Regards,
Karthik Raja

Loader.
Live Chat Icon For mobile
Up arrow icon