I have edited this question; I couldn't find a solution to my problem, and I have decided on catching the error and handling it instead.
I'm using a Spinner controller to accept Integer values. How do I catch this kind of error java.lang.NumberFormatException ? I'm getting this error when a user enters a character into the text edit box.
The Spinner is editable.
I really appreciate any help you can provide.
My code:
Spinner<Integer> mySpin = new Spinner<Integer>(50, 80, 50);
How can I catch the error and display a message to the user to indicate the error?
Exception in thread "JavaFX Application Thread"
java.lang.NumberFormatException: For input string: "d"
at
java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:660)
at java.base/java.lang.Integer.valueOf(Integer.java:991)
at javafx.base/javafx.util.converter.IntegerStringConverter.fromString(IntegerStringConverter.java:49)
at javafx.base/javafx.util.converter.IntegerStringConverter.fromString(IntegerStringConverter.java:35)
at javafx.controls/javafx.scene.control.Spinner.commitValue(Spinner.java:455)
at javafx.controls/javafx.scene.control.Spinner.lambda$new$3(Spinner.java:163)
at javafx.base/com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:348)
at javafx.base/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
at javafx.base/javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:72)
at javafx.graphics/javafx.scene.Node$FocusedProperty.notifyListeners(Node.java:8148)
at javafx.graphics/javafx.scene.Node.setFocused(Node.java:8201)
at javafx.graphics/javafx.scene.Scene$KeyHandler.setWindowFocused(Scene.java:4026)
at javafx.graphics/javafx.scene.Scene$KeyHandler.lambda$new$0(Scene.java:4048)
at javafx.base/com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:136)
at javafx.base/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
at javafx.base/javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:72)
at javafx.base/javafx.beans.property.ReadOnlyBooleanWrapper.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:103)
at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:111)
at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
at javafx.graphics/javafx.stage.Window.setFocused(Window.java:675)
at javafx.graphics/javafx.stage.Window$1.setFocused(Window.java:150)
at javafx.graphics/com.sun.javafx.stage.WindowHelper.setFocused(WindowHelper.java:112)
at javafx.graphics/com.sun.javafx.stage.WindowPeerListener.changedFocused(WindowPeerListener.java:64)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:126)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:40)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassWindowEventHandler.lambda$handleWindowEvent$4(GlassWindowEventHandler.java:176)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:174)
at javafx.graphics/com.sun.glass.ui.Window.handleWindowEvent(Window.java:1346)
at javafx.graphics/com.sun.glass.ui.Window.notifyFocus(Window.java:1325)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:831)