title: JavaFX - getScene() returns null
body: <p>I just started using JavaFX Scene Builder to build a small application.</p>
  
  <p>It is made up of a controller class 'Login.java' which belongs to 'login.fxml', in which the FXML file 'registrierung.fxml' is loaded via a method called 'registrationClicked(ActionEvent event)':</p>
  
  <pre><code>public class Login {
  
  @FXML
  private void registrationClicked(ActionEvent event){
      try{
          ((Node) (event.getSource())).getScene().getWindow().hide();
          FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/fxml/registrierung.fxml"));
          Parent root = (Parent) loader.load();
          Stage stage = new Stage();
          Scene scene = new Scene(root);      
          stage.setTitle("Registration");
          stage.setScene(scene);
          stage.setResizable(false);
          stage.show();
      } catch(IOException e){
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Now I want to get a reference to the stage of 'registrierung.fxml' in the controller class 'Registrierung.java' via the root node vboxRoot:</p>
  
  <pre><code>@FXML
  private VBox vboxRoot;
  
  Stage stage = (Stage) vboxRoot.getScene().getWindow();
  </code></pre>
  
  <p>However 'getScene()' always leads to a NullPointerException. The controller classes for both FXML files are adjusted in Scene Builder.</p>
  
  <p>This is how I set up the rood node in 'registrierung.fxml':</p>
  
  <pre><code>&lt;VBox fx:id="vboxRoot" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="267.0" prefWidth="355.0" stylesheets="@../css/styles.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="businesslogik.Registrierung"&gt;
  </code></pre>
  
  <p>What am I doing wrong? </p>