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
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 **
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.
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.
thanks for replay
i tried to do as you said but i still get the same error
B4X:
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
B4X:
*** 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)
File.Write map converts all values to strings. To save and retrieve objects (the list) you need to use the WriteB4xObject And ReadB4XObject methods of the RandomAccessFile library.
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
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
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
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)