Android Question [SOLVED]List Index Out of Bounds

nobbi59

Active Member
Licensed User
Longtime User
Hi Guys,

I have the following code:

B4X:
For k = 0 To (myMap.Size / 7) -1
        If slist.Get(k)= Value Then
        Else
        intlist.Add(k)
        End If
   
    Next
    Dim p As Int
    For p = 0 To intlist.Size
        titelliste.RemoveAt(intlist.Get(p))
    Next

And I get the Error java.IndexOutOfBounds Exception in the following line: titelliste.RemoveAt(intlist.Get(p))

But I dont know what I´m doing wrong

Hope you guys can help me
 

stevel05

Expert
Licensed User
Longtime User
It's difficult to tell without being able to see how you are filling the lists, but
For p = 0 To intlist.Size looks like a contender. If intlist is the same size as titelliste, then it should be
For p = 0 To intlist.Size -1
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
deleting items and forward progression will cause issues.

you have to do it backwarths since the array/list size changes constantly on deletion which leads to out of bounds.

B4X:
For p = intlist.Size-1 to 0 step -1
titelliste.RemoveAt(intlist.Get(p))
Next
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I agree with steve!
You don't give enough information !
Put a breakpoint at the line where you get the error and check the values.
That's the best way to debug programs.
You may also try:
For p = intlist.Size -1 To 0 Step -1
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…