Probably a beginner problem. but i can't get a list in map after Write it and Read again. i get this error message:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
B4X:
Dim mapSetting As Map
mapSetting.Initialize
Dim List1 As List
List1.Initialize2(Array As String("Name1", "Name2", "Name3"))
mapSetting.Put("MyList", List1)
File.WriteMap(File.DirInternal, "Setting.txt", mapSetting)
mapSetting = File.ReadMap(File.DirInternal, "Setting.txt")
Dim List2 As List = mapSetting.Get("MyList")
For Each s As String In List2
Log(s)
Next
File.WriteMap (and File .WriteList) convert all variables to strings and produce a text file. This means that they cannot save objects (like Lists) within Lists. You could use
KeyValueStore class instead (or RandomAccessFile.WriteObject).
File.WriteMap (and File .WriteList) convert all variables to strings and produce a text file. This means that they cannot save objects (like Lists) within Lists. You could use
KeyValueStore class instead (or RandomAccessFile.WriteObject).
Another option to KVS or RAF is to use json:
1. Put your list in your map like you have
2. then, JSONGenerator.Initialize(mapSetting)
3. Save json string to a file: