"Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference" when authenticting user on Android

dai15002 116 Reputation points
2020-11-27T08:38:33.063+00:00

Authenticating the user (using azure authentication provider) works fine. However, when the app is terminated and then launched, we are authenticating the user again and then we get the error Java.Lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference

When trying to authenticate again right after, it crashes with the error message System.InvalidOperationException: Authentication is already in progress.

Example code:

   try
                        {

                            ProviderHelper provider = ProviderHelper.Google;
                            var user = await AllInclusive.App.Client.LoginAsync(this, (MobileServiceAuthenticationProvider)provider, "myAppName");//crashes here

                        }catch(Exception e)
                        {
                            //first login when the app is launched after it has been terminated, we get the Java.Lang.NullPointerException error.
                            //when trying to login again, it crashes again with the error message "System.InvalidOperationException: Authentication is already in progress."
                            var messahe = e.Message;
                        }

What is the cause of the Java.Lang.NullPointerException error, do I need to create a new context for android when authenticating again? Any solutions for that error?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,561 questions
{count} votes

1 answer

Sort by: Most helpful
  1. dai15002 116 Reputation points
    2020-11-29T19:06:41.997+00:00

    Solved the root cause of this problem by just upgrading the Microsoft.Azure.Mobile.Client and Microsoft.Azure.Mobile.Client.SQLiteStore libraries from v.4.1.2 to v.4.2.0 and I no longer get the crash

    0 comments No comments