title: NullPointerException on ENTER-key press in JavaFX Application Thread
body: <p>I currently have the following situation:</p>
  
  <p>I want to make my application listen to user input. First, I did this with an invisible TextField, but this screwed up my design and I thought it was not sophisticated enough. So, I am now trying to make a onKeyPressed EventHandler on my upper FlowPane, like this:</p>
  
  <pre><code>public String input = "";
  @FXML public void listenToInput(KeyEvent key) {
  
      if (key.getCode() != KeyCode.ENTER) {
  
          if (key.getCode().isDigitKey() || key.getCode().isLetterKey()) {
              String newChar = key.getText();
              input = input.concat(newChar);
          }
  
      }
      else {
          this.addScanToList(input);
          input = "";
      }
  
  }
  </code></pre>
  
  <p>This is working for just plain text and digits. But as soon as I press <kbd>ENTER</kbd>, I get the following error:</p>
  
  <pre><code>Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
  at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.activate(TableViewBehaviorBase.java:915)
  at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.callAction(TableViewBehaviorBase.java:179)
  at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218)
  at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.callActionForEvent(TableViewBehaviorBase.java:208)
  at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$75(BehaviorBase.java:135)
  at com.sun.javafx.scene.control.behavior.BehaviorBase$$Lambda$146/1103773754.handle(Unknown Source)
  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$KeyHandler.process(Scene.java:3926)
  at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3872)
  at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2001)
  at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2463)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$346(GlassViewEventHandler.java:228)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$208/996795822.get(Unknown Source)
  at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:406)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227)
  at com.sun.glass.ui.View.handleKeyEvent(View.java:540)
  at com.sun.glass.ui.View.notifyKey(View.java:950)
  </code></pre>
  
  <p>Where I already thought of:</p>
  
  <ul>
  <li>The upper FlowPane has no focus, but then I gave it focus, but no result.</li>
  <li>The enter key does not get recognized, which could be true, because the 'else' of my listenToInput never gets entered.</li>
  </ul>
  
  <p><strong>EDIT 1:</strong></p>
  
  <ul>
  <li>The FlowPane does not have a 'setOnAction', so it does not know how to handle the <kbd>ENTER</kbd> press.</li>
  </ul>
  
  <p>Does anyone know what triggers this error? </p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>I changed onKeyPressed to onKeyReleased, and then my code runs properly, but I still get the error. Maybe it helps to know that.</p>
  
  <p><strong>Edit 3:</strong></p>
  
  <p>I tried to add the scan to the list with <kbd>ALT</kbd> instead of <kbd>ENTER</kbd>, and this works perfectly, so it has something to do with the <kbd>ENTER</kbd></p>