Probably a beginner problem. But I'm just not clear. When I write data into a map and then add it to a list Why do not I get it out the other way around?!? regards
B4X:
dim liste as list
'put some data into a list
Dim m As Map
m.Initialize
m.Put("id_user", From)
m.Put("message",Message)
m.Put("dtime", Zeit)
liste.Add(m)
'back from list to variable
Dim m As Map = liste.Get(1)
Dim msg As String = m.Get("message")
Apart from the index to the list (which starts at zero) your code should work:
B4X:
Dim From,Message,Zeit As String
Zeit=DateTime.Now
From= "abc@example.com"
Message="This is a message.More ... "
Dim liste As List
liste.Initialize
'put some data into a list
Dim m As Map
m.Initialize
m.Put("id_user",From)
m.Put("message",Message)
m.Put("dtime", Zeit)
Log("Map: " & m)
liste.Add(m)
Log(liste)
'back from list to variable
Dim m As Map = liste.Get(0) 'List index starts at zero
Log("Retrieved message" & m)
Dim msg As String = m.Get("message")
Log("Msg: " & msg)
This gives:
Map: (MyMap) {id_user=abc@example.com, message=This is a message.More ... , dtime=1496741186827}
(ArrayList) [{id_user=abc@example.com, message=This is a message.More ... , dtime=1496741186827}]
Retrieved message(MyMap) {id_user=abc@example.com, message=This is a message.More ... , dtime=1496741186827}
Msg: This is a message.More ...
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
I am surprised that you did not spot the lack of initialisation of the list object. If you were running in Debug mode, your first statement to add an item to the list would have shown up this error in the Debug log:
Error occurred on line: 65 (Main)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
...etc