title: NullPointerException when changing from scene with ListView
body: <p>I am getting a <code>NullPointerException</code> when changing from a scene with a <code>ListView</code>.</p>
  
  <p>I have a main "home" page, which loads <code>Main.fxm</code>l, with a <code>ListView</code>, that when populated, breaks the app and causes it to not be able to change scenes. It works fine if the <code>ListView</code> is not populated.</p>
  
  <p>Main controller that holds methods used by controllers for other scenes:</p>
  
  <pre><code>public class Controller implements Initializable {
      @FXML ListView&lt;String&gt; list;
      @FXML Button toLoginScreen;
      //other FXML elements
  
      public void changeView(String page, ActionEvent event) throws IOException {
          Parent parent = FXMLLoader.load(getClass().getResource(page));
          Scene scene = new Scene(parent);
          Stage stage = (Stage)((Node) event.getSource()).getScene().getWindow();
          stage.setScene(scene);
          stage.show();
      }
  
      @FXML
      private void loginButtonAction(ActionEvent event) throws IOException {
          changeView("Login.fxml", event);
      }
  
          //other methods
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          list.getItems().add("an item");
      }
  </code></pre>
  
  <p>The Main.fxml file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  //imports
  &lt;BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"&gt;
      &lt;top&gt;
          &lt;VBox BorderPane.alignment="CENTER"&gt;
              &lt;children&gt;
                  &lt;ToolBar&gt;
                      &lt;items&gt;
                          &lt;Button fx:id="toLoginPage" mnemonicParsing="false" onAction="#loginButtonAction" text="Login" /&gt;
                      &lt;/items&gt;
                  &lt;/ToolBar&gt;
              &lt;/children&gt;
          &lt;/VBox&gt;
      &lt;/top&gt;
      &lt;center&gt;
          &lt;SplitPane dividerPositions="0.5" BorderPane.alignment="CENTER"&gt;
              &lt;items&gt;
                  &lt;AnchorPane&gt;
                      &lt;children&gt;
                          &lt;AccordionprefHeight="356.0" prefWidth="246.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
                              &lt;panes&gt;
                                  &lt;TitledPane animated="false" text="List 1"&gt;
                                      &lt;content&gt;
                                          &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"&gt;
                                              &lt;children&gt;
                                                  &lt;ListView fx:id="list" prefHeight="280.0"   prefWidth="244.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"AnchorPane.topAnchor="0.0" /&gt;
                                              &lt;/children&gt;
                                          &lt;/AnchorPane&gt;
                                      &lt;/content&gt;
                                  &lt;/TitledPane&gt;
                              &lt;/panes&gt;
                          &lt;/Accordion&gt;
                      &lt;/children&gt;
                  &lt;/AnchorPane&gt;
                  &lt;AnchorPane /&gt;
              &lt;/items&gt;
          &lt;/SplitPane&gt;
      &lt;/center&gt;
  &lt;/BorderPane&gt;
  </code></pre>
  
  <p>Full error trace:</p>
  
  <pre><code>Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
  at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
  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:8411)
  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:3757)
  at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
  at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
  at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
  at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
  at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
  at com.sun.glass.ui.View.notifyMouse(View.java:937)
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
  at java.lang.Thread.run(Unknown Source)
  
  Caused by: java.lang.reflect.InvocationTargetException
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at sun.reflect.misc.Trampoline.invoke(Unknown Source)
  at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
  at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
  ... 48 more
  
  Caused by: javafx.fxml.LoadException:/path/Project/bin/application/Login.fxml
  at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
  at application.Controller.changeView(Controller.java:42)
  at application.loginController.loginButtonAction(loginController.java:33)
  ... 58 more
  
  Caused by: java.lang.NullPointerException
  at application.Controller.initialize(Controller.java:91)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
  ... 67 more
  </code></pre>
  
  <p>If I try to go from the main scene to the Login scene I get a NullPointerException at the</p>
  
  <pre><code>list.getItems().add("an item");
  </code></pre>
  
  <p>in the <code>Controller</code>'s <code>initialize</code> method.</p>