B4J Question Problem working with B4XCustomDialogs: Numberformatexception: empty String

GuyBooth

Active Member
Licensed User
Longtime User
I'm new to B4X Dialogs and I'm having problems with my first attempt.
My Dialog box has two text fields and two combo boxes. I want to disable the "OK" button until the combo box results are acceptable - for purposes of this test, both of them must have any value other than the first one in the list selected.

The relevant subs are:
B4X:
Sub btnCustom_Click
''' some code
dialog.setbuttonState(-1, False)    ' to set the ok button to disabled
dialog.setbuttonState(-3, True)        ' to set the Cancel button enabled
End sub

Sub fieldcbx1_SelectedIndexChanged (Index As Int)
    Check_CBXChanged
    Log("CBX1 Index")
End Sub
Sub fieldcbx2_SelectedIndexChanged (Index As Int)
    Check_CBXChanged
    Log("CBX1 Index")
End Sub

Sub Check_CBXChanged
    Dim index1 As Int = fieldcbx1.SelectedIndex
    Dim index2 As Int = fieldcbx2.SelectedIndex
    dialog.SetButtonState(-1, (index1 > 0 And index2 > 0))
End Sub
When I click on the combo box to select and item, the dialog.setbuttonstate(-1, (index1 > 0 and Index2 > 0)) throws this error:
B4X:
b4xdialog._getbutton (java line: 340)
java.lang.NumberFormatException: empty String
    at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
    at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.base/java.lang.Double.parseDouble(Double.java:549)
    at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:395)
    at b4j.example.b4xdialog._getbutton(b4xdialog.java:340)
    at b4j.example.b4xdialog._setbuttonstate(b4xdialog.java:493)
    at b4j.example.main._check_cbxchanged(main.java:580)
    at b4j.example.main._fieldcbx1_selectedindexchanged(main.java:587)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:442)
    at b4j.example.b4xcombobox$ResumableSub_RaiseEvent.resume(b4xcombobox.java:271)
    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(AccessController.java:391)
    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:832)
How should I be doing this? Can anyone see an error here?
I have attached an example with my code, it is based on the example on this forum.
 

Attachments

  • DialogTest.zip
    4.3 KB · Views: 161
Top