Android Question .RemoveAt(Index)

prokli

Active Member
Licensed User
Longtime User
I need help with an quite simple looking piece of code!
This line always fails " uplTiFiles.RemoveAt(0)" as shown in example next.

I am very confused because first Log() shows a list keeping up to 40 file names
and second Log() shows the first file in list.
So why is it not possible to remove this file from list???


Declaration in Service module

Sub Process_Globals

Private uplTiFiles As List

End Sub

somewhere I do this in a service module:

uplTiFiles = File.ListFiles("system/app")


and inside a timer I do this

Send_File(uplTiFiles.Get(0))
Log(uplTiFiles)
Log("removing file from list: " & uplTiFiles.Get(0))
'remove from list to avoid sending it again
uplTiFiles.RemoveAt(0) ' THIS ALWAYS FAILS!!
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I could be wrong, but shouldn't you prefix uplTiFiles with the name of the service module when called from outside of the service it was declared?
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
The error is because the File.ListFiles method return a "read only list", so you can't change it :)

You need to get the list by File.ListFiles, than copy this list in another "normal" list, so then you can delete each item from this list

Sergio
 
Upvote 0

prokli

Active Member
Licensed User
Longtime User
Thanks to all!

I get the error message:
java.lang.UnsupportedOperationException followed by a lot more lines of error code

@sirjo66: I am not sure what you are telling me!
What is a "normal" list?
I created a additional list as shown next:
Dim oList As List

and I assigned this list according to:

uplTiFiles = File.ListFiles("system/app")
oList = uplTiFiles

Result: I get the same error message

So any further idea?????
 
Upvote 0

prokli

Active Member
Licensed User
Longtime User
Attached image of complete error message!
 

Attachments

  • list problem.png
    list problem.png
    32.7 KB · Views: 213
Upvote 0
Top