B4J Question CheckComboBox - bug? [Solved - not a bug]

GuyBooth

Active Member
Licensed User
Longtime User
Working with a CheckComboBox. I generated the event <controlname>_CheckedChanged from the Designer, and was getting some very strange errors when using the code:
B4X:
Index = 1   ' for example
<ccbxname>.SetChecked(<ccbxname>.Items.IndexOf(index, True)

To check I was using the correct event name, I type Sub, space, Tab etc and had the same result.

I finally changed the "_CheckedChanged" to "_CheckChanged" to make it work [EDIT] except it didn't work because _CheckChanged never gets called.
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
The code you posted is incorrect
B4X:
<ccbxname>.SetChecked(<ccbxname>.Items.IndexOf(index, True)
should be
B4X:
<ccbxname>.SetChecked(<ccbxname>.Items.IndexOf(index), True)

but that could just be a typo when you posted it

The items in the control are basically just a list of strings

The <ccbxname>.Items.IndexOf(index) is looking for an item that matches
So if the items in your CheckedComboBox were
"one"
"two"
"three"
"four"

you could use <ccbxname>.Items.IndexOf("three") and get the index of the item with the value "three"

If you just want to set the second item checked then you could use (first item = 0)
B4X:
index = 1
<ccbxname>.SetChecked(index,True)

Your code works as expected (after the typo correction) and does indeed call _CheckedChanged.
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Your code works as expected (after the typo correction) and does indeed call _CheckedChanged.
Yes it was a typo, but all is not well with it. I tried to create a small project to demo, but the small project works fine. But here is what I have also found with my much larger project:
  1. The error is only thrown in debug mode.
  2. The _CheckedChanged sub appears to be called twice even though the SetChecked method is only called once.
  3. It is only thrown if the _CheckedChange exists, and occurs even if there is no code in the _CheckedChanged sub. Remove (or comment out) the _CheckedChange sub and the error does not occur.
  4. It doesn't make any difference whether the setting is to True or False
  5. A "CheckAll" method just before the SetChecked method runs without throwing any errors.
Here is the code as written. I have simplified the offending statement for clarity:
B4X:
Sub Setup_PGInitialData
    Log($"Setup_PGInitialData"$)
    ' … some Code not related to ccbx errors

    ' Clear the existing selections
'' This does NOT throw any errors:   
    ccbxMusicType.CheckAll(False)
Log("Setting ccbx selection")
    ' Add the new one
'' This throws errors in debug mode   
    ccbxMusicType.SetChecked(9, True)
' … Other code not related to the ccbx error:
Log("Ending sub")
End Sub
' This Is where the errors are thrown
' If this is commented out, no errors are thrown
Sub ccbxMusicType_CheckedChanged
    Log("CheckedChanged")
End Sub
When the code is run, in Debug mode I then get this (which I am led to believe I can ignore?):
B4X:
Unexpected event (missing RaiseSynchronousEvents): ccbxmusictype_checkedchanged
with a string of other related error logs.
But THEN the logs show this:
B4X:
Ending sub
CheckedChanged
CheckedChanged
Error occurred on line: 531 (MB_Add)
java.lang.IllegalArgumentException
 at jdk.internal.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:373)
 at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:181)
 at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
 at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
 at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
 at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
 at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
 at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1018)
 at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
 at java.base/java.security.AccessController.doPrivileged(Native Method)
 at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
 at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
 at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
 at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
 at java.base/java.lang.Thread.run(Thread.java:834)
Error occurred on line: 531 (MB_Add)
java.lang.NullPointerException
 at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:373)
 at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:181)
 at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
 at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
 at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
 at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
 at flm.b4j.tableviewextended.CellFactory$MyTableCell.updateItem(CellFactory.java:56)
 at javafx.controls/javafx.scene.control.TableCell.updateItem(TableCell.java:665)
 at javafx.controls/javafx.scene.control.TableCell.indexChanged(TableCell.java:469)
 at javafx.controls/javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:120)
 at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:539)
 at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.<init>(TableRowSkinBase.java:159)
 at javafx.controls/javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:89)
 at javafx.controls/javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:213)
 at javafx.controls/javafx.scene.control.Control.doProcessCSS(Control.java:897)
and many more lines that appear to have no bearing on this.
at which point the program stops.
Interesting that the "Error occurred on line: 531" appears twice.
Does this provide any clues? The statement on Line 531 is End Sub (from the _CheckedChanged sub).
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
How many items are in the CheckComboBox? ( ccbxMusicType.Items.Size)

Edit: It doesn't seem to matter if you try and set or get a non-existent item, no error is generated.

Yes it does fire the event twice.

I cannot reproduce your error.

Are you sure nothing else is writing values to the CheckComboBox?
 
Last edited:
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
How many items are in the CheckComboBox? ( ccbxMusicType.Items.Size)
About 15 … but I think I have found the culprit.
The calling sub calls the Setup_PGInitialData but immediately follows with a Sleep(0) before calling for a progress bar update:
B4X:
Setup_PGInitialData
Sleep(0)
dtmm.Show_Progress(pgbMB_Add, 100, True)
Removing the Sleep(0) fixes the problem.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…