Android Question problem with callsub in event routine

kpmais

Member
Licensed User
Longtime User
Hello folks,
I have a riddle to solve here and I hope someone had the same or a similar problem and can tell me.
I have an event routine that is triggered by a custom view (see below) The Custom View has a getName property.
This is queried with a Callsub routine. (Since several views call the same event, the name decides what happens next.)
Now the following happens when an event is triggered in debug mode:
- The subexist routine correctly recognizes the getName property
- if callsub(sender,"getname") is now called, I get an error with the following stack trace (the entire stack trace below).
Caused by: java.lang.RuntimeException: java.lang.Exception:
Sub getname signature does not match expected signature. at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336) at anywheresoftware.b4a.debug.Debug.CallSubNew(Debug.java:282) ...
32 more Caused by: java.lang.Exception:
Sub getname signature does not match expected signature. at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:321) ...
33 more

However, the signature is completely correct, unfortunately it is not that simple.
The error is only thrown in debug mode.
The release mode runs without any problems, as does the debug mode if the event routine is provided with a breakpoint and is debugged.
Likewise, there is no error in the Legacy Debugger.
Of course there are alternatives to my approach without Callsub.
However, I just want to understand what is happening here.
Or is it a bug in deb mode?
I am happy about every hint.

The Event Code:
B4X:
Sub alarmsetup_click
    Dim Name As String

    If SubExists(Sender,"getname") Then
        Name=CallSub(Sender,"getname") ' here is the error line
        Else
            Return
    End If

    Select Name
        Case "timeinput"
            SelMF.OpenForm("show_time_date_select",Null)
        Case "closepage"
            Close
    End Select
End Sub

the complete stacktrace of error message:

Error occurred on line: 103 (EditAndStoreAlarmForm)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug(Common.java:1082)
at de.peter.testlib.editandstorealarmform._alarmsetup_click(editandstorealarmform.java:155)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1114)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1061)
at de.hp_mais.cvlib.cvtextlink._lview_click(cvtextlink.java:400)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1114)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1061)
at de.hp_mais.cvlib.cvlabel._clabel_click(cvlabel.java:165)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub getname signature does not match expected signature.
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
at anywheresoftware.b4a.debug.Debug.CallSubNew(Debug.java:282)
... 32 more
Caused by: java.lang.Exception: Sub getname signature does not match expected signature.
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:321)
... 33 more
 

kpmais

Member
Licensed User
Longtime User
Thank you for your answers.
ok I understand that. sorry
Here I have a small sample project as a zip file.
omething else to mention: The callsub routine mentioned refers to a library.
Here in the example a small custom label.
If the custom class is placed in the project, the program also runs properly in debug mode (without breakpoint).
If the custom class is integrated as a library, the error mentioned occurs.
For testing, I equipped the test project with the custom class (custom class CLabel is in the zip file as the library TestLabelLib.jar, and as an inactive class in the project).
 

Attachments

  • TestProject.zip
    505.7 KB · Views: 121
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at your problem.

First, on my device the program with the library works as expected in Debug and in Release mode.
But i get the warning 'Sub 'getname' not found' in this line:
B4X:
Dim name As String = CallSub(Sender,"getname")

Then i unchecked the library and added the CLabel Class module.
I saw that you have these routines: Public getName and setName.
These routines are Property routines !
Modify your code as follows:
B4X:
Sub mylabel_click
    Private lbl As CLabel
    lbl = Sender
    Dim name As String = lbl.Name
Instead of:
B4X:
Sub mylabel_click
    Dim name As String = CallSub(Sender,"getname")
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Ruminations of a rather strange person (me ? ).

Since in the first post there were these lines of code:
B4X:
Sub alarmsetup_click
    Dim Name As String

    If SubExists(Sender,"getname") Then
        Name=CallSub(Sender,"getname") ' here is the error line
I thought that that event-routine could be called by different types of object (custom views?) and that some of them could not have the getName property, so the problem would be less simple, as you couldn't cast the Sender without knowing the type a priori.

If, on the other hand, the type of Sender object is known in advance, the thing is very simple (and in fact we must bear in mind that a sub getName is considered a property, while GetName would be a method).

B4X:
Sub alarmsetup_click

    Select Sender.As(YourClass).Name
        Case "a"
        Case "b"
        Case "c"
        Case Else
    End Select

End Sub
 
Last edited:
Upvote 0

kpmais

Member
Licensed User
Longtime User
Thanks for all the answers and the time you take for "my" problem.
Regarding the last answer:
I already wrote at the beginning that there are more ways to solve the task. I am interested in the behavior of the software in debug mode.
Why is he doing this?
to Klaus' answer:
The warning "not found" appears if the related routine is not in the project but in a library. I would also be very interested in why this is so.
Further:
When testing in debug mode, note the following (unfortunately I didn't mention it).
If you test in debug mode and set a breakpoint in the _click routine, the callsub statement will run fine.
If you then test again without a breakpoint in debug mode, it runs just as smoothly.
Once you have tested with Breakpoint, you must first "Clean the Project".
It took me at least 20 tries with amazement and shaking my head to see that.
It doesn't matter whether you use a real device or an emulation.
My behavior is always the same. An error occurs in debug mode without a breakpoint in the _click routine.
I can only assume that it is somehow related to the data that is written to the device used in debug mode.
However, I find the error message "Caused by: java.lang.Exception: Sub getname signature does not match expected signature" at least confusing.
The signature is absolutely correct.
 
Upvote 0

kpmais

Member
Licensed User
Longtime User
Thanks.
Ok, if you use the classname then it runs in debug mode.
But why doesn't it work if I pass it as a Sender Object?
I wonder. In Release or Legace Debug, the transfer as a sender also runs.
Why is that? I'm puzzled about that. It is possible that this behavior also leads to crashes elsewhere.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I used the Sender object!

B4X:
    Dim Name As String = Sender.As(CLabel).Name
   
    Select Name

the As method is used to carry out the casting-
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
This is just a guess on part but debug is slower so you might have a timing issue. I believe Sender is Global. I'm guessing some other code is Changing Sender to another type before your code finishes.
FYI I always Dim Var as Datatype = Sender. It has saved me a lot of time in debugging if nothing else because if it is wrong it fails right there,
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…