B4J Question Weird Menu JSON Error.

LWGShane

Well-Known Member
Licensed User
Longtime User
I'm re-doing the menu for my app and am receiving a "Value at 2 is null" error.

The Menu Code:
B4X:
[
    {Text: "File", Children:
    [
        {Text: "Open Image", Tag: "Open"},
        {Text: "Exit", Tag: "Exit"},
    ]},
    {Text: "Generate", Tag: "Generate", Children:
    [
        {Text: "All"},
        {Text: "Development Platforms"},
        {Text: "Social Platforms"},
        {Text: "-"},
        {Text: "Android"},
        {Text: "iOS"},
        {Text: "Windows", Children:
        [
            {Text: "Phone 8.0"},
            {Text: "Windows 10 Universal"},
        ]},
    ]},
    {Text: "Write", Tag: "Write"},
    {Text: "Help", Children:
    [
        {Text: "About"},
        {Text: "BitBucket Repository"},
    ]},
]

The Error Code:
B4X:
Program started.
org.json.JSONException: Value at 2 is null.
    at org.json.JSONArray.get(JSONArray.java:259)
    at anywheresoftware.b4j.objects.collections.JSONParser.convertObjToList(JSONParser.java:105)
    at anywheresoftware.b4j.objects.collections.JSONParser.convertObjToMap(JSONParser.java:94)
    at anywheresoftware.b4j.objects.collections.JSONParser.convertObjToList(JSONParser.java:109)
    at anywheresoftware.b4j.objects.collections.JSONParser.NextArray(JSONParser.java:65)
    at anywheresoftware.b4j.objects.MenuItemWrapper$MenuBarWrapper.parseMenusJson(MenuItemWrapper.java:247)
    at anywheresoftware.b4j.objects.MenuItemWrapper$MenuBarWrapper.build(MenuItemWrapper.java:234)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.DynamicBuilder.build(DynamicBuilder.java:16)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayoutHeader(LayoutBuilder.java:113)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayoutHeader(LayoutBuilder.java:154)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(LayoutBuilder.java:77)
    at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:76)
    at com.whiteholesoftware.iconstudio.main._appstart(main.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:593)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at com.whiteholesoftware.iconstudio.main.start(main.java:36)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)

Any ideas?
 

Daestrum

Expert
Licensed User
Longtime User
I got your menu working but can't post it as it goes screwy in the forum here's the zip
 

Attachments

  • menu1.zip
    384 bytes · Views: 226
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I think the main problem was the 'Write' top menu with no children, as that would have been item 2.
 
Upvote 0

LWGShane

Well-Known Member
Licensed User
Longtime User
@Daestrum Thanks for the help!

@Erel - First time designing a menu by hand, so I wasn't used to all of the quirks of the menu JSON.
 
Upvote 0
Top