Android Question firebase Object should first be initialized (FirebaseUser).

wangondu

Member
Licensed User
Longtime User
i have download the copy of the FirebaseStorage Example enabled uploaduser button and tried to click on the button during runtime but am getting the error saying "java.lang.RuntimeException: Object should first be initialized (FirebaseUser)." what could be the problem
my main code
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals

End Sub

Sub Globals
    Private btnUploadAuth As Button
    Private btnDownloadPublic As Button
    Private btnUploadUser As Button
    Private btnSignIn As Button
    Private lblUser As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume
    If Starter.auth.CurrentUser.IsInitialized Then SignedIn
End Sub

Public Sub SignedIn
    btnSignIn.Enabled = False
    btnUploadAuth.Enabled = True
    btnUploadUser.Enabled = True
    lblUser.Text = $"User: ${Starter.auth.CurrentUser.DisplayName}"$
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btnSignIn_Click
    Starter.auth.SignInWithGoogle
End Sub

Sub btnUploadUser_Click
    File.WriteString(File.DirInternalCache, "1.txt", "Only I can access this resource.")
    Starter.storage.UploadFile(File.DirInternalCache, "1.txt", $"/user/${Starter.auth.CurrentUser.Uid}/1.txt"$)
End Sub

Sub btnDownloadPublic_Click
    'You need to first upload a file from Firebase console.
    Starter.storage.DownloadFile("/public/1.txt", File.DirInternalCache, "1.txt")
   
End Sub

Sub btnUploadAuth_Click
    File.WriteString(File.DirInternalCache, "1.txt", "Any authenticated user can access this resource.")
    Starter.storage.UploadFile(File.DirInternalCache, "1.txt", $"/auth/1.txt"$)
    End Sub

Sub Storage_DownloadCompleted (ServerPath As String, Success As Boolean)
    ToastMessageShow($"DownloadCompleted. Success = ${Success}"$, True)
    If Not(Success) Then Log(LastException)
End Sub

Sub Storage_UploadCompleted (ServerPath As String, Success As Boolean)
    ToastMessageShow($"UploadCompleted. Success = ${Success}"$, True)
    If Not(Success) Then Log(LastException)
End Sub

starter service code
B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Public auth As FirebaseAuth
    Public storage As FirebaseStorage
    Private bucket As String = "gs://smspoa-fb19f.appspot.com"
End Sub

Sub Service_Create
    auth.Initialize("auth")
    storage.Initialize("storage", bucket)
End Sub

Private Sub Auth_SignedIn (User As FirebaseUser)
    Log($"Signed in: ${User}"$)
    CallSub(Main, "SignedIn")
End Sub


Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

what could be the error
 
Top