B4J Question CLV and java.lang.IndexOutOfBoundsException

MarcoRome

Expert
Licensed User
Longtime User
Hi All.
I have the following code.
If I try to delete the last record immediately it crashes (Release)
Example if I delete randomly (1,3,2,4) everything ok, but when I get to the last one it gives the error java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

B4X:
Sub lbl_cancello_extra_selezionato_MouseClicked (EventData As MouseEvent)
    Dim b As B4XView = Sender
    Dim index_uno As Int  = clv.GetItemFromView(b.Parent)
    Log("Index: " & index_uno)
    Try
        clv.RemoveAt(index_uno)
    Catch
        Log(LastException)
    End Try
End Sub

But if add Sleep(0) the same code work:

B4X:
Sub lbl_cancello_extra_selezionato_MouseClicked (EventData As MouseEvent)
    Dim b As B4XView = Sender
    Dim index_uno As Int = clv.GetItemFromView(b.Parent)
    Sleep(0)
    Log("Index: " & index_uno)
    Try
        clv.RemoveAt(index_uno)
    Catch
        Log(LastException)
    End Try
End Sub

Bug or what ?
 

Attachments

  • TestCLVIndex.zip
    3.6 KB · Views: 91

MarcoRome

Expert
Licensed User
Longtime User
Hi @Erel

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…