Android Question Object should first be initialized (StatusBarNotification)

Neojoy

Member
Licensed User
Longtime User
Hi,

Anybody knows how to fix this error:

B4X:
java.lang.RuntimeException: Object should first be initialized (StatusBarNotification).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.NotificationListenerWrapper$StatusBarNotificationWrapper.getNotification(NotificationListenerWrapper.java:199)
at com.myapp.notificationservice._listener_notificationposted(notificationservice.java:6497)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.NotificationListenerWrapper$NotificationListener.HandleIntent(NotificationListenerWrapper.java:134)
at com.myapp.notificationservice._service_start(notificationservice.java:11857)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.myapp.notificationservice.handleStart(notificationservice.java:109)
at com.myapp.notificationservice.access$000(notificationservice.java:17)
at com.myapp.notificationservice$1.run(notificationservice.java:80)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8512)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

B4X:
Sub Process_Globals
    Private listener As NotificationListener
    

Sub Service_Create
    listener.Initialize("listener")
    
Sub Service_Start (StartingIntent As Intent)
    If listener.HandleIntent(StartingIntent) Then
        Return
    End If

I don't know what is wrong and my app crash when this happens
 

Neojoy

Member
Licensed User
Longtime User
Post the code in Listener_NotificationPosted.

I think that I find out what is wrong

B4X:
Sub Listener_NotificationPosted (SBN As StatusBarNotification)

    Dim jno As JavaObject = SBN.Notification
    Dim extras As JavaObject = jno.GetField("extras")

        If OsVersion.SdkVersion >= 19 Then
            If SBN.IsInitialized Then
                extras.RunMethod("size", Null)

I was trying to get SBN.Notification before check if SBN was initialized, correct?
 
Upvote 0
Top