Android Question Firebase message Error

fishwolf

Well-Known Member
Licensed User
I don't undestand this error, help please

B4X:
PermissionResult=true
PermissionType=android.permission.WRITE_EXTERNAL_STORAGE
PermissionResult=true
FirebaseMessagging-SubscribeToTopics
FirebaseMessagging-SubscribeToTopics-InittializeFirebaseMessaging
Topic=fishwolf@gmail.com
Topic=fishwolf-at-gmail.com
firebasemessaging_subscribetotopics (java line: 391)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
    at it.software.castiel.infoagility.firebasemessaging._subscribetotopics(firebasemessaging.java:391)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6864)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1182)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6864)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:233)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
    ... 7 more
Caused by: java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
    at my.app.firebasemessaging._subscribetotopics(firebasemessaging.java:391)
i inizialize the object firebase
B4X:
Sub Service_Create
    
    Log ("FirebaseMessagging-Service_Create")
    
    fm.Initialize("fm")
      
End Sub

Public Sub SubscribeToTopics
Dim Topic As String
    
    Log("FirebaseMessagging-SubscribeToTopics")
    

    If fm.IsInitialized = False Then
        Log("FirebaseMessagging-SubscribeToTopics-InittializeFirebaseMessaging")
        fm.Initialize("fm")
    End If
    
    Topic = Main.gParamEmail
    Log ("Topic=" & Topic)
    Topic = Topic.Replace("@", "-at-")
    Log ("Topic=" & Topic)
    fm.SubscribeToTopic(Topic)
    
    Log("Token=" & fm.Token)
    
End Sub
 

GymReaper

Member
Licensed User
Where is this Service_Create Sub located? I assume in your FirebaseMessaging.bas file?

Do you have

fm1:
Public fm As FirebaseMessaging
in your Main.bas Process_Globals sub?

then in your Starter.bas Service_Create sub you should have

fm2:
    Main.fm.Initialize ("fm")
 

fishwolf

Well-Known Member
Licensed User
Where is this Service_Create Sub located? I assume in your FirebaseMessaging.bas file?

Do you have

fm1:
Public fm As FirebaseMessaging
in your Main.bas Process_Globals sub?

then in your Starter.bas Service_Create sub you should have

fm2:
    Main.fm.Initialize ("fm")
i have fm definition and initialize in FirebaseMessang Service
 

DonManfred

Expert
Licensed User
- The Service must have the name FirebaseMessaging . No other name will work. In a FirebaseMessang service it will not work.
- Also you should NOT use the starter Service for this.

See the Tutorial
 

fishwolf

Well-Known Member
Licensed User
- The Service must have the name FirebaseMessaging . No other name will work. In a FirebaseMessang service it will not work.
- Also you should NOT use the starter Service for this.

See the Tutorial
Yes, is FirebaseMessaging.

I have this problem with the same project in B4A 9.8 (PC1) and not with 9.5 (PC2) version.
I have downgrade PC1 from 9.8 to 9.5 but is the same. Before to update the PC1 work fine
B4X:
firebasemessaging_subscribetotopics (java line: 382)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
    at my.app.firebasemessaging._subscribetotopics(firebasemessaging.java:382)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6864)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1182)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6864)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:233)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
    ... 7 more
Caused by: java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
    at it.software.castiel.infoagility.firebasemessaging._subscribetotopics(firebasemessaging.java:382)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    ... 8 more
 

fishwolf

Well-Known Member
Licensed User
Please

- post your library version
- post the firebaseanalytics library version
- post your manifest

Looks like you are using an old integration. Or deprecated library versions. the newest are installed with the IDE. Yre you using V9.8 of B4A?
FirebaseNotification 1.21
FirebaseAnalitics 1.11
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="16" 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)

AddPermission (android.permission.GET_ACCOUNTS)
AddPermission (android.permission.WRITE_EXTERNAL_STORAGE)
'SetApplicationAttribute(android:debuggable, "true")
'SetApplicationAttribute(android:persistent, true)
'SetApplicationAttribute(android:allowTaskReparenting, true)
'End of default text.

AddReplacement($ADMOB_APP_ID$, ca-app-pub-xxx~yyy)

'************ Google Play Services Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)

CreateResourceFromFile(Macro, Core.NetworkClearText)
Versions.jpg
 

DonManfred

Expert
Licensed User
Top