title: Odd Java FXML NumberFormatException?
body: <p>Whenever I do an action, I get this</p>
  
  <pre><code>Button[id=gButton, styleClass=button]'Guess'
  gField content: 44
  Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
      at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1762)
      at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1645)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Node.fireEvent(Node.java:8216)
      at javafx.scene.control.Button.fire(Button.java:185)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3724)
      at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3452)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1728)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2461)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:348)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:273)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:382)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:553)
      at com.sun.glass.ui.View.notifyMouse(View.java:925)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
      at com.sun.glass.ui.win.WinApplication$$Lambda$37/728890494.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.reflect.InvocationTargetException
      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:483)
      at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
      at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
      at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1757)
      ... 47 more
  Caused by: java.lang.NumberFormatException: For input string: ""
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      at java.lang.Integer.parseInt(Integer.java:592)
      at java.lang.Integer.parseInt(Integer.java:615)
      at javafxapplication.FXMLDocumentController.handleButtonAction(FXMLDocumentController.java:44)
      ... 57 more
  </code></pre>
  
  <p>Notice the <code>NumberFormatException for input string: ""</code> - you can see my input on line 2, <code>gField content: 44</code> 
  Here's my <code>FXMLDocumentController.java</code>:</p>
  
  <pre><code>private Label gLabel;
  @FXML
  private Button rButton;
  @FXML
  private Button gButton;
  @FXML
  private SubScene colorBar;
  @FXML
  private TextField gField;
  
  @FXML
  private void handleButtonAction(ActionEvent event) {
      Object source = event.getSource();
      String guess = gField.getText();
      System.out.println("You clicked me!");
      System.out.println(source);
      if (source == gButton || source == gButton) {
          if (Integer.parseInt(guess) &gt; JavaFXApplication.nToGuess) {
              JavaFXApplication.nTries++;
              gLabel.setText("Too High!");
  
          } else if (Integer.parseInt(guess) &lt; JavaFXApplication.nToGuess) {
              JavaFXApplication.nTries++;
              gLabel.setText("Too Low!");
  
          } else if (Integer.parseInt(guess) == JavaFXApplication.nToGuess) {
              if (JavaFXApplication.nTries &gt; 1) {
                  gLabel.setText("Took you " + JavaFXApplication.nTries + " tries. Restarted.");
                  System.out.println("Took you " + JavaFXApplication.nTries + " tries. Restarted.");
              } else if (JavaFXApplication.nTries == 0) {
                  gLabel.setText("You are a hacker.");
                  System.out.println("You are a hacker.");
              } else if (JavaFXApplication.nTries == 1) {
                  gLabel.setText("It's taken you only 1 try.");
                  System.out.println("It's taken you only 1 try.");
              }
              JavaFXApplication.nTries = 0;
              JavaFXApplication.rand = new Random();
              JavaFXApplication.nToGuess = JavaFXApplication.rand.nextInt(100);
              System.out.println(JavaFXApplication.nToGuess);
          }
      } else if (source == rButton) {
          JavaFXApplication.nTries = 0;
          gLabel.setText("Game has been restarted.");
          JavaFXApplication.rand = new Random();
          JavaFXApplication.nToGuess = JavaFXApplication.rand.nextInt(100);
          System.out.println("Game restarted.\n" + JavaFXApplication.nToGuess);
      }
      gField.setText(null);
  }
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
      assert gButton != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";
      assert rButton != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";
      assert colorBar != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";
      assert gLabel != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";
      assert gField != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";
  
  
  }  
  </code></pre>
  
  <p>And here's my <code>JavaFXApplication.java</code>:</p>
  
  <pre><code>static int nTries = 0;
  static Random rand = new Random();
  static int nToGuess = rand.nextInt(100);
  @Override
  public void start(Stage stage) throws Exception {
  
      Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
  
      Scene scene = new Scene(root);
      stage.setScene(scene);
      stage.show();
  }
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      launch(args);
  }
  public static String nTriesTextGetter() {
      return Integer.toString(nTries);
  }
  </code></pre>
  
  <p>I know that in swing you have to use action event listener and <code>EventQueue.invokeLater</code> so that the logic doesn't run in the EDT thread, and this is my first application using JavaFX. Any explanation would be of great help.</p>