B4J Question combobox needing initializing despite creating in Globals

raphipps2002

Active Member
Licensed User
Longtime User
I have been learning b4j and have a strange issue I cant understand why it is happening. On one form i have added a combobox, and created a unique ID for it, saved the form and closed. As normal I Generated a New Member for this combobox and In Globals as follows:

B4X:
    Private cmbSystemCompanyID As ComboBox

On the main form the comboboxes seem to function just fine. can Add, clear items without the need to initialize. However, on a form called from this form, as I try to Add or clear items i get and error saying I need to initialize them. Why is this?

Error occurred on line: 2007 (Main)
java.lang.RuntimeException: Object should first be initialized (ComboBox).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
at anywheresoftware.b4j.objects.ComboBoxWrapper.getItems(ComboBoxWrapper.java:95)
at b4j.cashbook.main._loadsystemdata(main.java:2586)
at b4j.cashbook.main._btncashbookcopy_action(main.java:2152)
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: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:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$2.run(BA.java:165)
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)

B4X:
cmbCountry.Items.Clear
 

Daestrum

Expert
Licensed User
Longtime User
Is it on a layout designed by the internal designer ?
I've noticed you get a similar error if you try to use a control before the ???.rootpane.loadlayout("???") is executed.
 
Upvote 0

raphipps2002

Active Member
Licensed User
Longtime User
Ah yes I see. I used a routine to update all forms where I needed the same data in similar comboboxes. And yes unless the layout is loaded an error occurs. Perhaps its a bad habit from vb.net which doesnt care if form is loaded or not. So, I just surrounded the cmb.items.clear with try..catch...so if form is displayed it works and if not its caught. thanks once again
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You could check if the combobox is initialized:

B4X:
If cmb.isInitialized Then cmb.items.clear

Rather than use a Try Catch block
 
Upvote 0
Top