I all.
I have list with many items. And I have to remove some items and I use a for...next todo it. But when I remove an item, the size of list change to but the For...next run for the original list size and an error occur like
java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
How can do it without error?
Example code:
I have list with many items. And I have to remove some items and I use a for...next todo it. But when I remove an item, the size of list change to but the For...next run for the original list size and an error occur like
java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
How can do it without error?
Example code:
B4X:
Dim liste1 As List
liste1.Initialize
For x=0 To 10
liste1.Add(x)
Next
For x=0 To liste1.Size-1
Log (x & ") " & liste1.Get(x))
Next
Log ("size of liste1 = " & liste1.Size)
For x=0 To liste1.Size-1
If liste1.Get(x)= 3 Or liste1.Get(x)=5 Or liste1.Get(x)=8 Then
Log( "remove " & x & " value " & liste1.Get(x))
liste1.RemoveAt(x)
End If
Next