caccas Member Licensed User Longtime User Mar 2, 2014 #1 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
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
DonManfred Expert Licensed User Longtime User Mar 2, 2014 #2 Why you want to remove the NEXT item if the actual item is not an .png? I would say B4X: filelist.RemoveAt(i) should be correct. Upvote 0
Why you want to remove the NEXT item if the actual item is not an .png? I would say B4X: filelist.RemoveAt(i) should be correct.
derez Expert Licensed User Longtime User Mar 2, 2014 #3 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
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
DonManfred Expert Licensed User Longtime User Mar 2, 2014 #4 He will run into a ListindexOutOfBounds otherwise, correct. Upvote 0
caccas Member Licensed User Longtime User Mar 2, 2014 #5 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
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.
margret Well-Known Member Licensed User Longtime User Mar 2, 2014 #6 Instead of removing from filelist, add them to a second List when they match what you are looking for. Upvote 0
Instead of removing from filelist, add them to a second List when they match what you are looking for.