Android Question Problem with single record using Xml2Map

Mamus

New Member
Licensed User
i am using Xml2Map to convert record from my web service to displace on my forms successfully but noticed that it only works if the record set is more than one. If my query returns a single row the application with stop working with this message on the logs panel.

java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.util.List
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
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:6146)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

this is my code

Dim Query1 As String = "https://nepawahala.ng/DataSetService.aspx?edi=select top 1 question,answer,convert(varchar, date1, 107) as date2,(select top 1 fullname from visitors where visitors.id=visitorid) as fullname from qanda where id = " & Main.publicQID
Query1 = Query1.Replace(" ","%20")

myjob.Download(Query1)
wait for (myjob) jobdone (myjob As HttpJob)

If myjob.Success Then
' Label3.Text = myjob.GetString
Dim x2m As Xml2Map
x2m.Initialize
root = x2m.Parse(myjob.GetString)
Dim dataset As Map = root.Get("NewDataSet")
Dim Tables As List = dataset.Get("AlexRose")
For Each itemslistx As Map In Tables
Dim questionStr As String = itemslistx.Get("question")
question.Text = questionStr.Replace("</p>","").Replace("<p>","").Replace(CRLF,"").Trim
Dim su As StringUtils
question.Height = su.MeasureMultilineTextHeight(question, question.Text)
Dim answerStr As String = itemslistx.Get("answer")
answer.Text = answerStr.Replace("</p>","").Replace("<p>","").Replace(CRLF,"").Trim
answer.Height = su.MeasureMultilineTextHeight(answer, answer.Text)
Dim date2Str As String = itemslistx.Get("date2")
date1.Text = date2Str.Replace("</p>","").Replace("<p>","").Replace(CRLF,"").Trim
Dim fullnameStr As String = itemslistx.Get("fullname")
fullname.Text = fullnameStr.Replace("</p>","").Replace("<p>","").Replace(CRLF,"").Trim
Next
Else
Msgbox("You need to be online" ,"You are offline")
Activity.Finish
End If
myjob.Release
 

DonManfred

Expert
Licensed User
Longtime User
Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
You could try something like ..
B4X:
If dataset.Get("AlexRose") Is Map Then
    Dim Table As Map = dataset.Get("AlexRose")
          
    'extract data ...
Else
    Dim Tables As List = dataset.Get("AlexRose")
    For Each itemslistx As Map In Tables
    Dim questionStr As String = itemslistx.Get("question")
              
     'extract data
Next
 
Upvote 0
Top