Android Question FireBaseAuth error : ( AuthStateListener)' on a null object reference

Status
Not open for further replies.

WebQuest

Active Member
Licensed User
Hi guys I'm updating my app in playstore, I want to enter the FirebaseAuth service to access a database in the Firbase console. I performed all the steps necessary to associate my app to firebaseDatabase, I created a database for testing set the rules with Google access, I included in my app the FireBaseAuth libraries, for authentication, JdbcSQL to read and write in the FireBase database, and JavaObject. but I'm stuck at authentication. I have taken as an example projects present here in the community https://www.b4x.com/android/forum/threads/firebaseauth-authenticate-your-users.67875/#content
I generated the .Json file from the Firebase console and integrated it into this test project by renaming the Package with the name of the package of my app but I always get the same error :

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.auth.FirebaseAuth.addAuthStateListener(com.google.firebase.auth.FirebaseAuth$AuthStateListener)' on a null object reference



what is it due? I read that maybe it's a bug how can I fix it?

B4X:
Sub Process_Globals
    Private auth As FirebaseAuth
End Sub

Sub Globals
    Private lblName As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        auth.Initialize("auth")
    End If
    Activity.LoadLayout("1")
    If auth.CurrentUser.IsInitialized Then Auth_SignedIn(auth.CurrentUser)
End Sub

Sub btnSignIn_Click
    auth.SignInWithGoogle
End Sub

Sub btnSignOut_Click
    auth.SignOutFromGoogle
    lblName.Text = "Goodbye!"
End Sub

Sub Auth_SignedIn (User As FirebaseUser)
    Log("SignedIn: " & User.DisplayName)
    lblName.Text = "Hello: " & User.DisplayName
End Sub
   
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
1. Forumsearch is working
2. What is your manifestcontent?
3. What is firebasemessaging and firebaseanalytics version?
4. What B4A Version are you using?
5. You are using an old Android SDK?
 
Upvote 0

WebQuest

Active Member
Licensed User
Hi DonManfred I spent the night in the forum looking for the same problem and I followed all the tips of the other posts.

2. MANIFEST :
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile (Macro, FirebaseAnalytics.Firebase)

'************ Google Play Services Base (end) ************

'************ Firebase Base ************

CreateResourceFromFile("google-services", "google-services.json")
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(com.google.android.c2dm.permission.RECEIVE)
AddPermission(${applicationId}.permission.C2D_MESSAGE)
AddManifestText( <permission android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />)
AddApplicationText(
<receiver
          android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
          android:enabled="true">
        <intent-filter>
          <action android:name="com.google.android.gms.measurement.UPLOAD"/>
        </intent-filter>
      </receiver>

      <service
          android:name="com.google.android.gms.measurement.AppMeasurementService"
          android:enabled="true"
          android:exported="false"/>   
    <provider
            android:authorities="${applicationId}.firebaseinitprovider"
            android:name="com.google.firebase.provider.FirebaseInitProvider"
            android:exported="false"
            android:initOrder="100" />
      <receiver
          android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
          android:enabled="true">
        <intent-filter>
          <action android:name="com.google.android.gms.measurement.UPLOAD"/>
        </intent-filter>
      </receiver>

      <service
          android:name="com.google.android.gms.measurement.AppMeasurementService"
          android:enabled="true"
          android:exported="false"/>
    <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>
       <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
            android:exported="false" />
  <service
            android:name="com.google.firebase.iid.FirebaseInstanceIdService"
            android:exported="true">
            <intent-filter android:priority="-500">
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
)
'************ Firebase Base (end) ************
'************ Firebase Auth ************
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
AddApplicationText(
   <activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar"
                  android:excludeFromRecents="true"
                  android:exported="false" />

        <service
            android:name="com.google.android.gms.auth.api.signin.RevocationBoundService"
            android:exported="true"
            android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
)
'************ Firebase Auth (end) ************

3. FirbaseAnalytics Ver 1.00
4. Using B4A 8.00
I updated all the recommended packages with the B4A SDK Manager.
 
Upvote 0

WebQuest

Active Member
Licensed User
This is what the FireBase documentation says about the error:

FirebaseAuth.AuthStateListener


public static interface FirebaseAuth.AuthStateListener



Listener called when there is a change in the authentication state.

Use addAuthStateListener(AuthStateListener) and removeAuthStateListener(AuthStateListener) to register or unregister listeners.

Public Method Summary
abstract void
onAuthStateChanged(FirebaseAuth auth)
This method gets invoked in the UI thread on changes in the authentication state:
  • Right after the listener has been registered
  • When a user is signed in
  • When the current user is signed out
  • When the current user changes
Public Methods
FirebaseAuth auth)[/paste:font]

This method gets invoked in the UI thread on changes in the authentication state:

  • Right after the listener has been registered
  • When a user is signed in
  • When the current user is signed out
  • When the current user changes
Parameters
auth
use it to disambiguate which FirebaseAuth instance the event corresponds to, in the case where you are using more than one at the same time.


I tried to isolate the connection status check but I get the same message.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        auth.Initialize("auth")
    End If
    Activity.LoadLayout("1")
    'If auth.CurrentUser.IsInitialized Then Auth_SignedIn(auth.CurrentUser)
End Sub
 
Upvote 0

WebQuest

Active Member
Licensed User
I followed the first steps to the letter.

4. Add the manifest snippets to the manifest editor based on the services that you need.
The manifest at this point is thus:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

CreateResourceFromFile (Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile (Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile (Macro, FirebaseAuth.FirebaseAuth)


5. Follow the instructions of the specific libraries.
Now here have I followed the initialization instructions and method you still need?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
3. FirbaseAnalytics Ver 1.00
newest is 1.11
Make sure to update the internal library.

What is you firebasemessaging library version?

Your manifest looks OK now so far i can see.

Away from that i´m not sure what could be wrong, sorry.
 
Upvote 0

WebQuest

Active Member
Licensed User
Everything ok .. I have bypassed the function through a starter service and now it works ... I hope this question is useful to someone.
 
Upvote 0

drzamo

New Member
Licensed User
Help Me!
I can't get back. I'm going crazy.


java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.auth.FirebaseAuth.addAuthStateListener(com.google.firebase.auth.FirebaseAuth$AuthStateListener)' on a null object reference

Librery FirebaseAuth 1.06



Manifest:
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
CreateResourceFromFile (Macro, FirebaseAuth.FirebaseAuth)
'************ Google Play Services Base (end) ************

'************ Firebase Base ************

CreateResourceFromFile("google-services", "google-services.json")
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(com.google.android.c2dm.permission.RECEIVE)
AddPermission(${applicationId}.permission.C2D_MESSAGE)
AddManifestText( <permission android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />)
AddApplicationText(
<receiver
android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.measurement.UPLOAD"/>
</intent-filter>
</receiver>

<service
android:name="com.google.android.gms.measurement.AppMeasurementService"
android:enabled="true"
android:exported="false"/>
<provider
android:authorities="${applicationId}.firebaseinitprovider"
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:exported="false"
android:initOrder="100" />
<receiver
android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.measurement.UPLOAD"/>
</intent-filter>
</receiver>

<service
android:name="com.google.android.gms.measurement.AppMeasurementService"
android:enabled="true"
android:exported="false"/>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />
<service
android:name="com.google.firebase.iid.FirebaseInstanceIdService"
android:exported="true">
<intent-filter android:priority="-500">
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
)
'************ Firebase Base (end) ************
'************ Firebase Auth ************
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
AddApplicationText(
<activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:excludeFromRecents="true"
android:exported="false" />

<service
android:name="com.google.android.gms.auth.api.signin.RevocationBoundService"
android:exported="true"
android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
)
'************ Firebase Auth (end) ************
 

Attachments

  • logerror.jpg
    logerror.jpg
    229.7 KB · Views: 279
Upvote 0
Status
Not open for further replies.
Top