Sub Globals
Dim m As Map
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim m1 As Map
m1.Initialize
m1.Put("Key1", "Value1")
m1.Put("Key2", "Value2")
m.Initialize
m.Put("holdkey1", m1)
End Sub
Sub Activity_Resume
Dim m2 As Map
m2 = m.Get("holdkey1")
Log(m2.Get("Key2"))
End Sub
ardroid=[value1, value2, value3]
Dim mylsita As List
mylsita = shared.sources_map.GetValueAt(i)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 79 (Main)
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
at b4a.example.main._activity_create(main.java:491)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
** Activity (main) Resume **
Because shared.sources_map.GetValueAt(i) returns a String and not a List.
By putting inside the value a list instead of a string.How can i make it return a list ?
By putting inside the value a list instead of a string.
If you put a string in map (map.put(key,string)), map.get(key) will return a string.
If you put a list in map (map.put(key,list)), map.get(key) will return a list.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim test As Map
Dim test2 As Map
Dim myList As List
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
test.Initialize
test2.Initialize
myList.Initialize
myList.Add("http://url.com/rss.xml")
myList.Add("ارديويد")
myList.Add("tech")
test.Put("ardroid",myList)
myList.Clear
File.WriteMap(File.DirRootExternal,"extramap.map",test)
Log("done")
End Sub
Sub Activity_Resume
test2 = File.ReadMap(File.DirRootExternal,"extramap.map")
myList = test2.Get("ardroid")
Log(myList)
End Sub
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
done
** Activity (main) Resume **
main_activity_resume (java line: 368)
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
at b4a.example.main._activity_resume(main.java:368)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at b4a.example.main.afterFirstLayout(main.java:108)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Sub Activity_Resume
Private Buffer As String
test2 = File.ReadMap(File.DirRootExternal, "extramap.map")
Buffer = test2.Get("ardroid")
myList.AddAll(Array As String(Buffer))
Log(myList)
End Sub
Try this code:
B4X:Sub Activity_Resume Private Buffer As String test2 = File.ReadMap(File.DirRootExternal, "extramap.map") Buffer = test2.Get("ardroid") myList.AddAll(Array As String(Buffer)) Log(myList) End Sub
Also, remove myList.Clear from your code.
** Activity (main) Create, isFirst = true **
done
** Activity (main) Resume **
(ArrayList) [http://url.com/rss.xml, ارديويد, tech, [http://url.com/rss.xml, ارديويد, tech]]
plase past the project hereI just have the same code you have and I can see the list populated.
B4X:** Activity (main) Create, isFirst = true ** done ** Activity (main) Resume ** (ArrayList) [http://url.com/rss.xml, ارديويد, tech, [http://url.com/rss.xml, ارديويد, tech]]
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim test As Map
Dim test2 As Map
Dim myList As List
Dim myList2 As List
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
test.Initialize
test2.Initialize
myList.Initialize
myList2.Initialize
myList.Add("http://url.com/rss.xml")
myList.Add("ارديويد")
myList.Add("tech")
test.Put("ardroid",myList)
File.WriteMap(File.DirRootExternal,"extramap.map",test)
Log("done")
End Sub
Sub Activity_Resume
test2 = File.ReadMap(File.DirRootExternal, "extramap.map")
myList2.AddAll(Array As String( test2.Get("ardroid")))
Log(myList2.Get(0))
End Sub
Sub Activity_Resume
Private Buffer As String
Private Items() As String
test2 = File.ReadMap(File.DirRootExternal, "extramap.map")
Buffer = test2.Get("ardroid")
Buffer = Buffer.Replace("[", "").Replace("]", "")
Items = Regex.Split(",", Buffer)
myList = Items
For I = 0 To myList.Size - 1
Log("Item: " & myList.Get(I))
Next
End Sub
hi
is it possible to have More than one value for a single map key ?
ex:
map.get1(user)
map.get2(user)
map.get3(user)
so that would get three value for a single key
is that possible , what is an alternative to the pas to so such thing ?
Type InfoType(device As String,string1 As String,string2 As String,string3 As String)
Dim M1 As Map : M1.Initialize
Dim info As InfoType : info.Initialize
info.device="android"
info.string1="value1"
info.string2="value2"
info.string3="value3"
M1.Put(user,info)
Dim getinfo As InfoType=M1.Get(user)
Log(getinfo.string1)