B4J Question CallSubDelayed causes exception for sub not found [problem fixed itself...]

Didier99

Member
Licensed User
In a class module, I have the following code:
B4X: Copy
Sub doStuff()
    ' do stuff...
    CallSubDelayed( Me, "setHeight" )
End Sub    ' SetRows()

Private Sub setHeight
    Log( "Height = " & frmMessage.WindowHeight )
End Sub ' setHeight

and I get this:
B4X: Copy
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: Sub setheight was not found.
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:523)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:494)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:568)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub setheight was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:514)
    ... 9 more
Caused by: java.lang.Exception: Sub setheight was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:118)
    ... 11 more
 
In B4X, routines whose names begin with "set" and "get" are considered properties; this is probably the error. Change the name to SetHeight.


P.S.
No, this code work as expected:
B4X: Copy
Sub Class_Globals
   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub

Public Sub DoIt
    CallSubDelayed(Me, "setHeight")
End Sub

Public Sub setHeight
    Log("set")
End Sub
 
Last edited:
Upvote 0
In B4X, routines whose names begin with "set" and "get" are considered properties; this is probably the error. Change the name to SetHeight.


P.S.
No, this code work as expected:
B4X: Copy
Sub Class_Globals
 
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub

Public Sub DoIt
    CallSubDelayed(Me, "setHeight")
End Sub

Public Sub setHeight
    Log("set")
End Sub
Interestingly, the problem has fixed itself as I was fixing other (mundane) issues... Always makes me very uncomfortable...

On this project, I regularly get an unusual error when I recompile after making changes. I have not looked at the details (I need to) but simply recompiling again with no change allow the program to run normally, so I have not dug into that one yet.
 
Last edited:
Upvote 0
Back
Top