Adding item to list

rossati

Active Member
Licensed User
Longtime User
Hello

I try to add an item to a list, but java get the unsupportedoperationexception error:

Sub insertlistDir(dir As String) As List
Dim lst As List
lst = File.ListFiles(dir)
lst.SortCaseInsensitive(True)
'If dir.indexOf2("/",1) > -1 Then lst.InsertAt(0,"..")
lst.add("..")
Return lst
End Sub
...
//BA.debugLineNum = 286;BA.debugLine="lst.add(\"..\")";
_lst.Add((Object)(".."));
...

what is wrong?

John Rossati
 

spillo3d96

Member
Licensed User
Longtime User
First you have to initialize your list : Lst.Initialize
And then to add an item: Lst.AddSingleLine("Item #" & i) or Lst.Add()
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I've read that file.listfiles returns a read-only list. perhaps this is causing the error. could you try capitalizing a new list and copy the contents of the previous one? maybe it works.

Update: Try this:

B4X:
Dim lst As List
lst.Initialize 
lst.AddAll (File.ListFiles(dir))
lst.SortCaseInsensitive(True)
'If dir.indexOf2("/",1) > -1 Then lst.InsertAt(0,"..")
lst.add("..")
Return lst
 
Last edited:
Upvote 0

rossati

Active Member
Licensed User
Longtime User
Thanks to all

it is solved, the first error is the list must be initialised, the second is I can't manipulate a read only list wich seems is the case of File.ListFiles.

John Rossati
 
Upvote 0
Top