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:

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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…