Android Question Problem parsing JSON format

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everyone. Could anybody help me with this error ?
error appear in line 10
B4X:
For Each colTable As Map In Table
Thank you.
Error occurred on line: 101 (Pag_articole)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
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.debug.Debug.delegate(Debug.java:262)
at b4a.example.pag_articole._b4xpage_created(pag_articole.java:68)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1055)
at b4a.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1023)
at b4a.example.b4xpagesmanager._showpage(b4xpagesmanager.java:395)
at b4a.example.b4xpages._showpage(b4xpages.java:96)
at b4a.example.pag_bon._btn_ad_articol_bon_click(pag_bon.java:88)
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:351)
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:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7869)
at android.widget.TextView.performClick(TextView.java:14958)
at android.view.View.performClickInternal(View.java:7838)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29362)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

B4X:
Dim gen As JSONGenerator
    gen.Initialize(DBUtils.ExecuteJSON(Starter.sql,"SELECT IName,ISelPrice FROM items",Null,0,Array As String(DBUtils.DB_TEXT,DBUtils.DB_TEXT)))
    Dim JSONString As String
    JSONString = gen.ToPrettyString(4)
    Log(JSONString)
    Dim parser As JSONParser
    parser.Initialize(JSONString)
    Dim root_ As  Map = parser.NextObject
    Dim Table As List = root_.Get("Table")
    For Each colTable As Map In Table   
        Dim ItemName As String = colTable.Get("iName")
        Dim ItemPrice As String = colTable.Get("iSelPrice")
        Log($"Item Name : ${ItemName} Item Price ${ItemPrice}"$)
    Next
 

DonManfred

Expert
Licensed User
Longtime User
Post the json
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
ExecuteJSON: SELECT IName,ISelPrice FROM items
{
"root": [
{
"IName": "Coca Cola 0,33 l",
"ISelPrice": "2.22"
},
{
"IName": "Pepsi Cola 0,33 l",
"ISelPrice": "3.33"
},
{
"IName": "Fanta Portocale 0,33 l",
"ISelPrice": "4"
},
{
"IName": "Nestea 0,33 l",
"ISelPrice": "5"
},
{
"IName": "Pepsi 0,5 l",
"ISelPrice": "6"
},
{
"IName": "Pepsi light 0,5 l",
"ISelPrice": "7"
},
{
"IName": "Mirinda 0,33 l",
"ISelPrice": "8"
},
{
"IName": "Pepsi Twist 0,33 l",
"ISelPrice": "9"
},
{
"IName": "Sprite 0,33 l",
"ISelPrice": "10"
},
{
"IName": "7Up 0,33 l",
"ISelPrice": "11"
},
{
"IName": "Hamburger",
"ISelPrice": "10"
},
{
"IName": "Ecler",
"ISelPrice": "4.34"
},
{
"IName": "Amandina",
"ISelPrice": "5.55"
},
{
"IName": "Dobos",
"ISelPrice": "6.34"
},
{
"IName": "Nestea Piersici -Doza 0,33 L",
"ISelPrice": "4.11"
},
{
"IName": "Banane",
"ISelPrice": "4.76"
},
{
"IName": "Caise",
"ISelPrice": "6.81"
},
{
"IName": "Pere",
"ISelPrice": "7.66"
},
{
"IName": "Ananas",
"ISelPrice": "10.17"
},
{
"IName": "Prune",
"ISelPrice": "7.46"
},
{
"IName": "Zmeura",
"ISelPrice": "28.57"
},
{
"IName": "Capsuni",
"ISelPrice": "10.08"
},
{
"IName": "Cirese",
"ISelPrice": "5.23"
},
{
"IName": "Visine",
"ISelPrice": "5.45"
},
{
"IName": "Portocale",
"ISelPrice": "6.99"
},
{
"IName": "Morcovi",
"ISelPrice": "2"
},
{
"IName": "Rosii Chery",
"ISelPrice": "5.12"
},
{
"IName": "Castraveti",
"ISelPrice": "3.1"
},
{
"IName": "Usturoi",
"ISelPrice": "4.5"
},
{
"IName": "Ceapa Rosie",

Message longer than Log limit (4000). Message was truncated.
 
Upvote 0
Top