Android Question List.RemoveAt Problem

caccas

Member
Licensed User
Longtime User
Hey all,

Dim filelist As List
Dim strAux As String

filelist = File.ListFiles(File.DirInternal)

For i = 0 To filelist.Size - 1

strAux = filelist.Get(i)
If strAux.IndexOf(".png") < 0 Then
filelist.RemoveAt(i+1)
End If

Next

In the code above when execute filelist.RemoveAt(i+1) i get this error java.lang.UnsupportedOperation Exception.

I can not understand what is happening.

Please help.

Thank you
 

derez

Expert
Licensed User
Longtime User
The problem is that when you remove an item the list changes and there are less items, not the original list.size.
The way to do it is for i = list.size -1 to 0 step -1
 
Upvote 0

caccas

Member
Licensed User
Longtime User
Thank you for your replay, but not work.

Look

For i = filelist.Size - 1 To 0 Step -1

strAux = filelist.Get(i)
If strAux.IndexOf(".png") < 0 Then
filelist.RemoveAt(i-1)
End If

Next

I try RemoveAt with i and i -1 but no work i get same error.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…