Android Question Weird crash with Wait For

techknight

Well-Known Member
Licensed User
Longtime User
Perhaps I am doing something wrong (probably) but I am having a weird crash with Wait For...

Here is the code in question:

B4X:
'*******************************************************************************************************************************************
'Class Module Callbacks                                                                                                                       *
'*******************************************************************************************************************************************
'Called by EdgeConnection. Any status generated by the EDGEConnection class will end up here.
Public Sub EDGEConnection_HandleStatus(Status As Int)
    '0 = Connected and operating
    '1 = Connection Error on MQTT Connect
    '2 = MQTT has disconnected
    '3 = Invalid scoreboard version
    '4 = Timeout occured attempting to connect to the MQTT Server
    '5 = Timeout occured from Scoreboard display handling commands
    '6 = POST Error occured during connection to a physical scoreboard
    '7 = Timeout occured during POST on a physical scoreboard
    '8 = Invalid password supplied to scoreboard
    Select Case Status
        Case 0        'System up and operational
            StatusCode = 2        'Set Status as operational
        Case 1
            StatusCode = 19        'MQTT Connection error       
        Case 2
            StatusCode = 17        'Scoreboard disconnected.
        Case 3
            StatusCode = 20
        Case 4
            StatusCode = 19
        Case 5
            StatusCode = 3
        Case 6
            StatusCode = 4
        Case 7
            StatusCode = 21
        Case 8
            StatusCode = 6
    End Select
   
    If Connecting = True Then CallSubDelayed2(Me, "Status_Event", Status)        'Tell the pending HandleConnection to resume and handle the response.
End Sub

'Called from HMIConnection class. Power on/off events will fire this.
'Connect = true when powering on. False when powering off.
Public Sub HMIConnection_HandleConnection(Connect As Boolean) As ResumableSub
    Dim StatusCode As Int
    If Connect = True Then         'We are connecting to the scoreboard display    
        Connecting = True
        EDGE.Connect            'Connect to the Display/Scoreboard instance
        Wait For Status_Event (Response As Int)        'Wait for something forwarded from EDGEConnection_HandleStatus
        Connecting = False
        Return Response
    Else                        'We are disconnecting from the scoreboard display
        Connecting = False
        Wait For (EDGE.Disconnect) Complete (Result As Boolean)        'Disconnect from the scoreboard.
        StatusCode = 17
        Return 255                'Send a random response from a disconnect, as it doesn't really matter the state of the system
    End If
End Sub

Here is the crash:
B4X:
Error occurred on line: 935 (Scorekeeper)
java.lang.NumberFormatException: For input string: "b4j.example.scorekeeper$ResumableSub_HMIConnection_HandleConnection@79698539"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:412)
    at b4j.example.hmiconnection$ResumableSub_mqtt_MessageArrived.resume(hmiconnection.java:904)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:153)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:102)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
    at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1103)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
    at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:170)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
    at b4j.example.main.main(main.java:29)

Line 935 is the Wait For line:
1675782671596.png


Not entirely sure why its tossing a number format exception, im only passing an integer down the line.

Calling instance to HAndleConnection: (From another class)
1675783443326.png


thoughts?
 
Last edited:

techknight

Well-Known Member
Licensed User
Longtime User
Why are you not waiting for a Status_Event on disconnect like you do on connect. Does disconnect not raise a Status_Event?
t?

Because its not used for the Disconnect event. Only connect. Status codes change during the lifetime of the connection, which is why that event is there. But I only need to "forward" those to the connect instance during the connecting period, so thats why I have the wait for there.

I do have a wait for on disconnect, but i dont need the response. This was a class used in other apps too, which is why its there to begin with.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I think i figured it out. I needed an additional Wait For from the parent caller as well, so i had to wrap the CallSub2 in its own wait for complete.
 
Upvote 0
Top