title: I'm getting an java.lang.reflect.InvocationTargetException exception in JavaFX app and I have no idea how to fix it
body: <p>I'm building a small D&amp;D side project, but having trouble navigating my way through JavaFX. I'm attempting to move through several scenes while remaining on the same stage. I'm using an MVC design and passing though the primaryStage whenever the controller is called. However, when I try to call from my UI class and get the stage from my controller, it throws a InvocationTargetException.</p>
  <p>Main Class:</p>
  <pre><code>package dnd;
  
  import javafx.application.Application;
  import javafx.stage.Stage;
  
  public class DnD extends Application {
      @Override
      public void start(Stage primaryStage) throws Exception { 
          primaryStage.setTitle(&quot;Dungeons and Dragons&quot;);
          StartMenuCtrl startMenuCtrl = new StartMenuCtrl(primaryStage);
          primaryStage.show();        
      }
  
      public static void main(String[] args) {
          launch(args);
      }   
  }
  </code></pre>
  <p>Start Menu Controller Class:</p>
  <pre><code>package dnd;
  
  import javafx.stage.Stage;
  
  public class StartMenuCtrl {
      private final StartMenuUI startMenuUI;
      private final Stage primaryStage;
  
      public StartMenuCtrl(Stage primaryStage) {
          this.startMenuUI = new StartMenuUI(this);
          this.primaryStage = new Stage();        
      }
      
      public void newButtonIsPressed() {
          System.out.println(&quot;New Button is pressed&quot;);
      }
      
      public void createButtonIsPressed() {
          System.out.println(&quot;Create Button is pressed&quot;);
          CreateCharCtrl createCharCtrl = new CreateCharCtrl(primaryStage);
      }
      
      public void loadButtonIsPressed() {
          System.out.println(&quot;Load Button is pressed&quot;);
      }
      
      public void joinButtonIsPressed() {
          System.out.println(&quot;Join Button is pressed&quot;);
      }
      
      public Stage getStage() {
          return this.primaryStage;
      }
  }
  </code></pre>
  <p>Start Menu UI Class:</p>
  <pre><code>package dnd;
  
  import javafx.scene.Group;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.text.Font;
  import javafx.scene.text.Text;
  import javafx.stage.Stage;
  
  public class StartMenuUI {
      private final StartMenuCtrl startMenuCtrl;
      private final Text title;
      private final Button newBtn;
      private final Button createBtn;
      private final Button loadBtn;
      private final Button joinBtn;
  
      public StartMenuUI(StartMenuCtrl startMenuCtrl) {
          this.startMenuCtrl = startMenuCtrl;
          this.title = new Text();
          this.newBtn = new Button(&quot;New Game&quot;);
          this.createBtn = new Button(&quot;Create Character&quot;);
          this.loadBtn = new Button(&quot;Load Saved Game&quot;);
          this.joinBtn = new Button(&quot;Join Game&quot;);
          initComponents();
      }
      
      private void initComponents() {
          Group root = new Group(title, newBtn, createBtn, loadBtn, joinBtn);
          Scene scene = new Scene(root, 1280, 720);
          Stage stage = startMenuCtrl.getStage();
          stage.setScene(scene);
      }
  }
  </code></pre>
  <p>Error:</p>
  <pre><code>Exception in Application start method
  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:498)
      at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
      at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
      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:498)
      at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  Caused by: java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: java.lang.NullPointerException
      at dnd.StartMenuUI.initComponents(StartMenuUI.java:70)
      at dnd.StartMenuUI.&lt;init&gt;(StartMenuUI.java:25)
      at dnd.StartMenuCtrl.&lt;init&gt;(StartMenuCtrl.java:10)
      at dnd.DnD.start(DnD.java:11)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
      ... 1 more
  </code></pre>
  <p>Any help would be appreciated! I'm very early in the project so drastic change tips would be appreciated as well :)</p>