B4J Question Menu Items

Fabrice La

Active Member
Licensed User
I used the
Private Sub CollectMenuItems(Menus AsMap, Items AsList) in
https://www.b4x.com/android/forum/bookmarks/?type=post&id=358367 And I have the following problem :

B4X:
Private menus As  Map ' in Process_Globals

menus.Initialize
CollectMenuItems(menus, mainMenuBar.Menus)
Dim mi As MenuItem = menus.Get("slqLoaderSaveMn")
mi.Enabled = False

Private Sub CollectMenuItems(menusMap As Map, Items As List)
   For Each mi As MenuItem In Items
     If mi.Text <> Null And mi.Text <> "" Then menusMap.Put(mi.Text, mi)
     If mi Is Menu Then
       Dim mn As Menu = mi
       CollectMenuItems(menusMap, mn.MenuItems)
     End If
   Next
End Sub

Error in line "mi.Enabled = False"

java.lang.RuntimeException: Object should first be initialized (MenuItem).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
at anywheresoftware.b4j.objects.MenuItemWrapper.setEnabled(MenuItemWrapper.java:91)
at b4j.example.main._applistart(main.java:749)
at b4j.example.main._resetlayout(main.java:1338)
at b4j.example.main._appstart(main.java:1090)
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:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
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:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
 
Top