Read List from Map

D

Deleted member 103

Guest
Hi,

I have a general problem with reading the list of map.

error= java.lang.ClassCastException: java.lang.String

Here is my code:
B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim map1,map2 As Map
   Dim list1 As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
   map1.Initialize
   map2.Initialize
   
   list1.Initialize   
   list1.AddAll(Array As String("1","2","3","4"))   
   map1.Put("list1",list1)

   File.WriteMap(File.DirDefaultExternal,"test.map",map1)
   
   map2=File.ReadMap(File.DirDefaultExternal,"test.map")
   
   Dim lst As List
   lst.Initialize
   lst=map2.GetValueAt(0)
   'lst.AddAll(Array As String(map2.GetValueAt(0)))
   
   Dim Nr As Int
   For i = 0 To lst.Size -1
      Nr=lst.Get(i)
      Log("Nr=" & Nr)
   Next
End Sub
 

Attachments

  • MapAndList.zip
    5.6 KB · Views: 225
D

Deleted member 103

Guest
I've now so solved, it's OK?

B4X:
Sub Activity_Create(FirstTime As Boolean)
   map1.Initialize
   map2.Initialize
   
   list1.Initialize   
   list1.AddAll(Array As String("1","2","3","4"))   
   map1.Put("list1",list1)

   File.WriteMap(File.DirDefaultExternal,"test.map",map1)
   
   map2=File.ReadMap(File.DirDefaultExternal,"test.map")
   
   Dim lst As List
   lst.Initialize
   
   [COLOR="Blue"]Dim strTmp() As String
   strTmp=Array As String(map2.GetValueAt(0))
   strTmp(0)=strTmp(0).SubString2(1,strTmp(0).Length -1)
   lst.Addall(Regex.Split(",",strTmp(0)))[/COLOR]
   
   Dim Nr As Int
   For i = 0 To lst.Size -1
      Nr=lst.Get(i)
      Log("Nr=" & Nr)
   Next
End Sub
 
Upvote 0
Top