B4J Question Spinner with Sender

rdkartono

Member
Licensed User
Longtime User
in my code, there are several labels, several checkboxes, and several spinners.

Initialization codes are as below :
B4X:
            Dim tr As TXTableRow = TXTable.Get(ii)
            Dim lbl_description As Label
            lbl_description.Initialize("lbldescription")
            lbl_description.Text = tr.Description
            lbl_description.Tag = tr
            Dim lbl_IP As Label
            lbl_IP.Initialize("lblIP")
            lbl_IP.Text = tr.IP
            lbl_IP.Tag = tr
            Dim lbl_enabled As CheckBox
            lbl_enabled.Initialize("lblenabled")
            lbl_enabled.Text = ""
            lbl_enabled.Checked = tr.Enabled
            lbl_enabled.Tag = tr
            Dim lbl_volin As Spinner
            lbl_volin.Initialize("lblvolin")
            lbl_volin.SetNumericItems(0,15,1,tr.VolumeInput)
            lbl_volin.Tag = tr

and events are like below :

B4X:
'IP address is about to change
Private Sub lblIP_MouseClicked (EventData As MouseEvent)
    If EventData.ClickCount<2 Then Return
    If Not(Sender Is Label) Then Return
    Dim lbl As Label = Sender
    If lbl.IsInitialized=False Then Return
    Dim tr As TXTableRow = lbl.Tag
    If tr.IsInitialized=False Then Return
   
End Sub

'enabled is about to change
Private Sub lblenabled_CheckedChange(Checked As Boolean)
    If Not(Sender Is CheckBox) Then Return
    Dim lbl As CheckBox = Sender
    If lbl.IsInitialized=False Then Return
    Dim tr As TXTableRow = lbl.Tag
    If tr.IsInitialized=False Then Return
    tr.Enabled = Checked
    save_TXTable
   
End Sub


'volume input is about to change
Private Sub lblvolin_ValueChanged (Value As Object)
    If Not(Sender Is Spinner) Then Return
    Dim spn As Spinner = Sender
    If spn.IsInitialized=False Then Return
    Dim tr As TXTableRow = spn.Tag
    If tr.IsInitialized=False Then Return
    tr.VolumeInput = Value
    save_TXTable
    If Main.barixdevice.DeviceCollection.ContainsKey(tr.IP) Then
        Main.barixdevice.ChangeVolumeInput(tr.IP,tr.VolumeInput)
    End If
End Sub

The problem is when i compile it, show error as below :
B4J version: 5.50
Parsing code. (0.03s)
Compiling code. (0.15s)
Compiling layouts code. (0.23s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
B4J line: 168
If Not(Sender Is Spinner) Then Return
javac 1.8.0_65
src\b4j\example\transmittering.java:195: error: illegal start of type
if (__c.Not(__c.Sender(ba) instanceof <any>)) {
^
1 error

It seems that these lines
If Not(Sender Is Spinner) Then Return
Dim spn As Spinner = Sender
caused problem. If I comment all lines in spinner ValueChanged event, B4J can compile correctly.

Is spinner in B4J can't use Sender ?
Why the others, like label and checkbox can use Sender ?
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Combobox works with sender without problem.

According to your initialization, you do not need to verify if the sender is a combobox. Yet

You could add an intermidiate variable

B4X:
Private Sub lblvolin_ValueChanged (Value As Object)
    'combobox and all the other nodes inherit from this class
    dim n as node = sender 
    If Not(n Is Spinner) Then Return
    Dim spn As Spinner = Sender
    If spn.IsInitialized=False Then Return
    Dim tr As TXTableRow = spn.Tag
    If tr.IsInitialized=False Then Return
    tr.VolumeInput = Value
    save_TXTable
    If Main.barixdevice.DeviceCollection.ContainsKey(tr.IP) Then
        Main.barixdevice.ChangeVolumeInput(tr.IP,tr.VolumeInput)
    End If
End Sub
 
Upvote 0

rdkartono

Member
Licensed User
Longtime User
I tried to follow Enrique's answer by intermediate variable nn as node :
B4X:
Dim nn As Node = Sender
    Dim spn As Spinner = nn
    If spn.IsInitialized=False Then Return
    Dim tr As TXTableRow = spn.Tag
    If tr.IsInitialized=False Then Return
    tr.VolumeInput = Value
    save_TXTable
    reload_TXtable
    If Main.barixdevice.DeviceCollection.ContainsKey(tr.IP) Then
        Main.barixdevice.ChangeVolumeInput(tr.IP,tr.VolumeInput)
    End If

Still producing same error :
B4X:
B4J version: 5.50
Parsing code.    (0.04s)
Compiling code.    (0.10s)
Compiling layouts code.    (0.04s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
B4J line: 213
Dim spn As Spinner = nn
javac 1.8.0_65
src\b4j\example\transmittering.java:302: error: illegal start of type
_spn.setObject((<any>)(_nn.getObject()));
                ^
1 error

Spinner is not same as combobox, if I force it from spinner to combobox, program can run, later show error as follow :
B4X:
transmittering._show_transmitter_form (java line: 496)
java.lang.RuntimeException: java.lang.ClassCastException: javafx.scene.control.Spinner cannot be cast to javafx.scene.control.ComboBox
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
    at anywheresoftware.b4a.BA$1.run(BA.java:215)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method)
    at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:218)
    at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511)
    at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
    at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:583)
    at javafx.stage.Stage.showAndWait(Stage.java:474)
    at anywheresoftware.b4j.objects.Form.ShowAndWait(Form.java:215)
    at b4j.example.transmittering._show_transmitter_form(transmittering.java:496)
    at b4j.example.main._menubar1_action(main.java:227)
    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:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.BA$1.run(BA.java:215)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: javafx.scene.control.Spinner cannot be cast to javafx.scene.control.ComboBox
    at b4j.example.transmittering._lblvolin_valuechanged(transmittering.java:298)
    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:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    ... 27 more

So still unsolved.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
oh yes yes, you are right, i was translating in my mind spinner (B4A) = combobox (B4J).
Yes, that is definitly a bug.

but because you are using only the tag on your sub, you can keep it with node

B4X:
Dim nn As Node = Sender
Dim tr As TXTableRow = nn.Tag
 
Upvote 0
Top