B4J Question Compilation problem

PatrikCavina

Active Member
Licensed User
Hi to all

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
   
    Private fx As JFX
    Private MainForm As Form
   
    Private maxNodes As Int = 5
    Private counter As Int = 0
   
    Private field(maxNodes) As TextField
    Private del(maxNodes) As Button
   
    Private TableView1 As TableView
    Private insert As Button
   
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   
    MainForm = Form1
    MainForm.RootPane.LoadLayout("a") 'Load the layout file.
   
    MainForm.Show
   
End Sub


Sub insert_MouseClicked (EventData As MouseEvent)
   
    If Not(counter<maxNodes) Then Return
   
    field(counter).Initialize("field")
    del(counter).Initialize("del")
   
    field(counter).Id = counter
    del(counter).Id = counter
   
   
    Dim o() As Object = Array As Object(field(counter),del(counter))
   
    TableView1.Items.Add(o)
   
    counter = counter + 1
   
End Sub


Sub del_MouseClicked (EventData As MouseEvent)
   
    Dim b As Button = Sender
   
    If EventData.PrimaryButtonPressed Then
   
        Dim delButtonID As Int = b.Id
       
        For i = delButtonID + 1 To TableView1.Items.Size-1
           
            Dim o() As Object = TableView1.Items.Get(i)
                       
            Dim n() As Node = o
           
            For j = 0 To n.Length-1
               
                n(j).Id = n(j).Id - "1"
               
            Next
           
        Next
       
        TableView1.Items.RemoveAt(delButtonID)
        counter = counter - 1
       
    Else
       
        Log(b.Id)
       
    End If
   
End Sub


'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
   
    Return True

End Sub

When i compiled and i used the function "del_MouseClicked" i received this error:

B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 64 (Main)
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lanywheresoftware.b4j.objects.NodeWrapper$ConcreteNodeWrapper;
    at b4j.example.main._del_mouseclicked(main.java:132)
    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:614)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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:102)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:90)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
    at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    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:745)

Instead when i set a breakpoint anywhere in the code and i compiled line per line with "Step In" command the code worked without errors.
How is possible?
What i want is that all id of nodes correspond to line where they are in TableView
 

Daestrum

Expert
Licensed User
Longtime User
As far as I can re-create what you are doing it seems this line
B4X:
Dim n() As Node = o

is the culprit. If you click the last item in table it works fine, any item before last triggers a similar error to yours.

I changed it to
B4X:
Dim n(2) As Node  ' I had 2 columns in table
n(0) = o(0)
n(1) = o(1)
...

and now I can click on the first table item without error and it re-sequences the id's for the remaining items.
 
Upvote 0
Top