B4J Question [SOLVED] Deleting the last entry in a CustomListView causes error

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello community,

I used to fill a CustomListView with some data from SQL and it works ...
... but if i want to delete the last Item of the CustomListView it shows the error-message "java.lang.IndexOutOfBoundsException: Index: 1, Size: 1" (see Logfile) and the App crashes:
customlistview._getrawlistitem (java line: 445)
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at anywheresoftware.b4a.objects.collections.List.Get(List.java:105)
at b4j.example.customlistview._getrawlistitem(customlistview.java:445)
at b4j.example.customlistview$ResumableSub_PanelClickHandler.resume(customlistview.java:771)
at b4j.example.customlistview._panelclickhandler(customlistview.java:747)
at b4j.example.customlistview._panel_mouseclicked(customlistview.java:738)
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:91)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:93)
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.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:394)
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$358(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
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$152(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

This is wrong, because in the CustomListView are shown 2 Items (therefore the CustomListView.Size should be = 2) and the Index should be = 1 ... and so there couldn't be an error.

How can i prevent this crash? Try/Catch doesn't work here (and it is not a correct solution anyway).
 

mangojack

Well-Known Member
Licensed User
Longtime User
Post the code that deletes the last item.
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
Hi mangojack,
thank you for your assistance ...
Post the code that deletes the last item.
... here is the code:
B4X:
    '-- den aktuellen Index des angeklickten "Buttons" (beginnend mit "0") ermitteln --
    Dim Index As Int = Layout_008_CustomListView_001.GetItemFromView(Sender)
    Log("-- 5144 -- Index = GetItemFromView(Sender): "&Index&"")
   
    '-- den Value beim aktuellen Index des angeklickten "Buttons" ermitteln --
    Dim Value As String = Layout_008_CustomListView_001.GetValue(Index)
    Log("-- 5146 -- Value: "&Value&"")
   
    '-- Datensatz LÖSCHEN --
    SQL1.ExecNonQuery("DELETE FROM Schulbildung WHERE SBD_030 = '"&Value&"' ")
 
Last edited:
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
I found the error ... it was not in this code.
It was caused by an additional code 5 lines later ... thank you for your help!
 
Upvote 0
Top