B4J Question How to fix error when set "value" in table view?


Sub mi_Action
    Dim mi As MenuItem = Sender
End Sub

'------------------------Set value in Table -------------------------
Sub GetLabel(RowIndex As Int, CellIndex As Int) As Label
    Dim row() As Object = tblLuaChonDN.Items.Get(RowIndex)
    Return row(CellIndex)
End Sub

Sub SetCellValue(RowIndex As Int, CellIndex As Int, Value As String)
    GetLabel(RowIndex, CellIndex).Text = Value
End Sub

The message error:
Error occurred on line: 145
java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.Labeled
    at anywheresoftware.b4j.objects.LabeledWrapper.setText(LabeledWrapper.java:26)
    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.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA$1.run(BA.java:215)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:748)
I am a newbje, Please Help me to solve this error.
Many thanks.


Thanks Erel, I mean that:
I load access file data into tableview and I have one columns cells of table is still empty after load data.
So I right click and choose the list from menu popup. The value of menu popup will be set into cell (in empty columns above).
I use SetCellValue function of your table example but I received the massage as "String cannot be cast to javafx.scene.control.Labeled"
You said that: "Based on the error message you have added a row by adding strings instead of calling CreateRow."
I don't know how to fix this error above. Please share your code here. Thanks.
Upvote 0


I solved this problem by using SQL to UPDATE a value of menu popup into the cell (when i right click) of database. And then I load the new data into tableview.
I don't use function SetCellValue.
Upvote 0