H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Oct 20, 2019 #1 i searched a lot about method enable me to load XML file to sqlite itried this code Code: Dim xm As Xml2Map xm.Initialize Dim root As Map = xm.Parse(File.ReadString(File.DirRootExternal, "css2.xml")) Dim mp As Map= root.Get("NewDataSet") Dim entries As List = mp.Get("Table")'<----error line DBUtils.InsertMaps(SQL, "css2", entries) and my xml code is <?xml version="1.0" encoding="UTF-8"?> <NewDataSet> <Table> <sq>10002134</sq> <nm>eeeeeee</nm> <ar>56</ar> <crd>02110050704</crd> <crdtyp>1</crdtyp> <ph>0</ph> <dlv>0</dlv> <gr>2</gr> <mr>0</mr> <dc>0</dc> <nw>0</nw> <prntd>6</prntd> </Table> </NewDataSet> Click to expand... and the error was Caused by: java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.util.List Click to expand... i tried to modify the XML file but no benefit i hope find solution thank in advance Last edited: Oct 20, 2019
i searched a lot about method enable me to load XML file to sqlite itried this code Code: Dim xm As Xml2Map xm.Initialize Dim root As Map = xm.Parse(File.ReadString(File.DirRootExternal, "css2.xml")) Dim mp As Map= root.Get("NewDataSet") Dim entries As List = mp.Get("Table")'<----error line DBUtils.InsertMaps(SQL, "css2", entries) and my xml code is <?xml version="1.0" encoding="UTF-8"?> <NewDataSet> <Table> <sq>10002134</sq> <nm>eeeeeee</nm> <ar>56</ar> <crd>02110050704</crd> <crdtyp>1</crdtyp> <ph>0</ph> <dlv>0</dlv> <gr>2</gr> <mr>0</mr> <dc>0</dc> <nw>0</nw> <prntd>6</prntd> </Table> </NewDataSet> Click to expand... and the error was Caused by: java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.util.List Click to expand... i tried to modify the XML file but no benefit i hope find solution thank in advance
DonManfred Expert Licensed User Longtime User Oct 20, 2019 #2 Code: Dim entries As Map = mp.Get("Table")' It returns a MAP, not a LIST! Upvote 0
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Oct 20, 2019 #3 @DonManfred how to get the list from in side the map??? i tries the Code: Dim entries As Map = mp.values but it was the same error i copied that code example works successfully and the xml file was the same Upvote 0
@DonManfred how to get the list from in side the map??? i tries the Code: Dim entries As Map = mp.values but it was the same error i copied that code example works successfully and the xml file was the same
DonManfred Expert Licensed User Longtime User Oct 20, 2019 #4 HAH said: Dim entries As List = mp.Get("Table")'<----error line Click to expand... raises an error. Caused by: java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.util.List Click to expand... i told you the solution. you are now using another code. Another issue. You are not giving enough informations. :-( Upvote 0
HAH said: Dim entries As List = mp.Get("Table")'<----error line Click to expand... raises an error. Caused by: java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.util.List Click to expand... i told you the solution. you are now using another code. Another issue. You are not giving enough informations. :-(
DonManfred Expert Licensed User Longtime User Oct 20, 2019 #5 HAH said: but it was the same error Click to expand... I strongly suggest to watch the collections tutorial video to understand the difference between lists and maps and their keys and/or values. Code: Dim mp As Map= root.Get("NewDataSet") for each k as string in mp.Keys log(k&"="&mp.get(k)) next What is the output? Upvote 0
HAH said: but it was the same error Click to expand... I strongly suggest to watch the collections tutorial video to understand the difference between lists and maps and their keys and/or values. Code: Dim mp As Map= root.Get("NewDataSet") for each k as string in mp.Keys log(k&"="&mp.get(k)) next What is the output?
DonManfred Expert Licensed User Longtime User Oct 20, 2019 #6 HAH said: and my xml code is Click to expand... there is no LIST inside btw. Upvote 0
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Oct 20, 2019 #7 DonManfred said: I strongly suggest to watch the collections tutorial video to understand the difference between lists and maps and their keys and/or values. Code: Dim mp As Map= root.Get("NewDataSet") for each k as string in mp.Keys log(k&"="&mp.get(k)) next What is the output? Click to expand... the out is : Table={sq=10002134, nm=محمد حسين علي الشيباني, ar=56, crd=02110050704, crdtyp=1, ph=0, dlv=0, gr=2, mr=0, dc=0, nw=0, prntd=6} Upvote 0
DonManfred said: I strongly suggest to watch the collections tutorial video to understand the difference between lists and maps and their keys and/or values. Code: Dim mp As Map= root.Get("NewDataSet") for each k as string in mp.Keys log(k&"="&mp.get(k)) next What is the output? Click to expand... the out is : Table={sq=10002134, nm=محمد حسين علي الشيباني, ar=56, crd=02110050704, crdtyp=1, ph=0, dlv=0, gr=2, mr=0, dc=0, nw=0, prntd=6}
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Oct 20, 2019 #8 DonManfred said: there is no LIST inside btw. Click to expand... <?xml version="1.0" encoding="UTF-8"?> <NewDataSet> <Table> <sq>10002134</sq> <nm>eeeeeee</nm> <ar>56</ar> <crd>02110050704</crd> <crdtyp>1</crdtyp> <ph>0</ph> <dlv>0</dlv> <gr>2</gr> <mr>0</mr> <dc>0</dc> <nw>0</nw> <prntd>6</prntd> </Table> </NewDataSet> Upvote 0
DonManfred said: there is no LIST inside btw. Click to expand... <?xml version="1.0" encoding="UTF-8"?> <NewDataSet> <Table> <sq>10002134</sq> <nm>eeeeeee</nm> <ar>56</ar> <crd>02110050704</crd> <crdtyp>1</crdtyp> <ph>0</ph> <dlv>0</dlv> <gr>2</gr> <mr>0</mr> <dc>0</dc> <nw>0</nw> <prntd>6</prntd> </Table> </NewDataSet>
DonManfred Expert Licensed User Longtime User Oct 20, 2019 #9 again. there is no list inside the xml. Upvote 0
DonManfred Expert Licensed User Longtime User Oct 20, 2019 #10 HAH said: the out is : Table={sq=10002134, nm=محمد حسين علي الشيباني, ar=56, crd=02110050704, crdtyp=1, ph=0, dlv=0, gr=2, mr=0, dc=0, nw=0, prntd=6} Click to expand... so mp does contain another map in the key "Table". Code: Dim mp As Map= root.Get("NewDataSet") Dim table As Map= mp.Get("Table") for each k as string in table.Keys log(k&"="&table.get(k)) next Last edited: Oct 21, 2019 Upvote 0
HAH said: the out is : Table={sq=10002134, nm=محمد حسين علي الشيباني, ar=56, crd=02110050704, crdtyp=1, ph=0, dlv=0, gr=2, mr=0, dc=0, nw=0, prntd=6} Click to expand... so mp does contain another map in the key "Table". Code: Dim mp As Map= root.Get("NewDataSet") Dim table As Map= mp.Get("Table") for each k as string in table.Keys log(k&"="&table.get(k)) next