JavaFX:线程“JavaFX 应用程序线程”中的异常 java.lang.RuntimeException:java.lang.reflect.InvocationTargetException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41371446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:19:41  来源:igfitidea点击:

JavaFX: Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

javajavafx

提问by alioukahere

I'm working on JavaFX project and I've an error like this:

我正在处理 JavaFX 项目,但出现如下错误:

Logout
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.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:8413)
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.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.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.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.access00(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:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent4(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
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.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null(GtkApplication.java:139)
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:498)
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:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 52 more
Caused by: java.lang.NullPointerException
at gn.kahere.car.manager.view.DrawerContentController.logoutAction(DrawerContentController.java:56)
... 62 more

My MainApp.java

我的主应用程序.java

package gn.kahere.car.manager;

import java.io.IOException;

import gn.kahere.car.manager.view.DrawerContentController;
import gn.kahere.car.manager.view.LoginController;
import gn.kahere.car.manager.view.RootLayoutController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class MainApp extends Application {

    private Stage primaryStage;
    private AnchorPane rootLayout;

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("Car Manager");

        // Prevent the window resizing
        this.primaryStage.setResizable(false);

        showLogin();
    }

    /**
     * Show the login page
     */
    public void showLogin() {
        try {
            // Load login page
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("view/Login.fxml"));
            AnchorPane login = (AnchorPane) loader.load();

            // Set the scene containing the login page
            Scene scene = new Scene(login);
            primaryStage.setScene(scene);

            // Give the controller access to the main application
            LoginController controller = loader.getController();
            controller.setMainApp(this);

            // Show the scene
            primaryStage.show();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Initializes the root layout
     */
    public void initRootLayout() {
        try {
            // Load root layout
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
            rootLayout = (AnchorPane) loader.load();

            // Give the controller access to the main application
            RootLayoutController controller = loader.getController();
            controller.setMainApp(this);

            // Get the DrawerContentController
            FXMLLoader drawerLoader = new FXMLLoader();
            drawerLoader.setLocation(MainApp.class.getResource("view/DrawerContent.fxml"));
            drawerLoader.load(); // Load the fxml file
            DrawerContentController drawerController = drawerLoader.getController();
            drawerController.setMainApp(this);

            // Show the scene containing the root layout
            Scene scene = new Scene(rootLayout);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

My RootLayoutController.java

我的 RootLayoutController.java

package gn.kahere.car.manager.view;

import java.io.IOException;

import com.jfoenix.controls.JFXDrawer;
import com.jfoenix.controls.JFXHamburger;
import com.jfoenix.transitions.hamburger.HamburgerBasicCloseTransition;

import gn.kahere.car.manager.MainApp;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;

public class RootLayoutController {

    // Reference to the main application
    @SuppressWarnings("unused")
    private MainApp mainApp;

    @FXML
    private JFXHamburger hamburger;

    @FXML
    private JFXDrawer drawer;


    /**
     * Controller
     */
    public RootLayoutController() {

    }

    /**
     * Initializes the controller class.
     */
    @FXML
    private void initialize() {
        try {
            VBox box = FXMLLoader.load(getClass().getResource("DrawerContent.fxml"));
            drawer.setSidePane(box);

            HamburgerBasicCloseTransition burgerTask = new HamburgerBasicCloseTransition(hamburger);
            burgerTask.setRate(-1);

            hamburger.addEventHandler(MouseEvent.MOUSE_PRESSED, (e) -> {
                burgerTask.setRate(burgerTask.getRate() * -1);
                burgerTask.play();

                if(drawer.isShown())
                    drawer.close();
                else
                    drawer.open();
            });
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Is called by the main application to give a reference back to itself
     * 
     * @param mainApp
     */
    public void setMainApp(MainApp mainApp) {
        this.mainApp = mainApp;
    }

}

RootLayout.fxml

根布局文件

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXDrawer?>
<?import com.jfoenix.controls.JFXHamburger?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="700.0" prefWidth="1000.0" stylesheets="@style.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gn.kahere.car.manager.view.RootLayoutController">
   <children>
      <JFXHamburger fx:id="hamburger" layoutX="946.0" layoutY="24.0" stylesheets="@style.css" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0">
         <cursor>
            <Cursor fx:constant="HAND" />
         </cursor>
      </JFXHamburger>
      <JFXDrawer fx:id="drawer" defaultDrawerSize="200.0" prefHeight="700.0" prefWidth="200.0" stylesheets="@../../../../../../bin/gn/kahere/car/manager/view/style.css" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0">
         <effect>
            <DropShadow />
         </effect>
      </JFXDrawer>
   </children>
</AnchorPane>

DrawerContentController.java

抽屉内容控制器.java

package gn.kahere.car.manager.view;

import gn.kahere.car.manager.MainApp;
import javafx.fxml.FXML;

public class DrawerContentController {

    // Reference to the main application
    private MainApp mainApp;


    /**
     * Controller
     */
    public DrawerContentController() {

    }

    @FXML
    private void initialize() {
        System.out.println("Drawer");
    }

    @FXML
    private void homeAction() {
        System.out.println("Home");
    }

    @FXML
    private void addCarAction() {
        System.out.println("Add Car");
    }

    @FXML
    private void listCarsAction() {
        System.out.println("List Cars");
    }

    @FXML
    private void searchAction() {
        System.out.println("Search");
    }

    @FXML
    private void agentsAction() {
        System.out.println("Agents");
    }

    @FXML
    private void profileAction() {
        System.out.println("Profile");
    }

    @FXML
    private void logoutAction() {
        System.out.println("Logout");
        mainApp.showLogin();
    }

    /**
     * Is called by the main application to give a reference back to itself
     * 
     * @param mainApp
     */
    public void setMainApp(MainApp mainApp) {
        this.mainApp = mainApp;
    }

}

DrawerContent.fxml

抽屉内容.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXButton?>
<?import java.lang.String?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="200.0" stylesheets="@style.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gn.kahere.car.manager.view.DrawerContentController">
   <children>
      <Pane prefHeight="150.0" prefWidth="200.0" styleClass="side-menu-header" stylesheets="@style.css">
         <children>
            <Text fill="WHITE" layoutX="14.0" layoutY="131.0" strokeType="OUTSIDE" strokeWidth="0.0" text="MAMADOU ALIOU DIALLO">
               <font>
                  <Font size="12.0" />
               </font>
            </Text>
            <ImageView fitHeight="62.0" fitWidth="66.0" layoutX="14.0" layoutY="44.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@../../../../../../img/user/avatar.png" />
               </image>
            </ImageView>
         </children>
      </Pane>
      <TextFlow prefHeight="18.0" prefWidth="200.0" style="-fx-background-color: #f0f8ff;" styleClass="navigation" stylesheets="@style.css">
         <children>
            <Text strokeType="OUTSIDE" strokeWidth="0.0" text="PRINCIPAL NAVIGATION" wrappingWidth="176.49267578125" />
         </children>
      </TextFlow>
      <JFXButton buttonType="RAISED" onAction="#homeAction" prefHeight="50.0" prefWidth="199.0" style="-fx-background-color: #ff033e;" stylesheets="@style.css" text="HOME" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <styleClass>
            <String fx:value="menu-btn" />
            <String fx:value="btn" />
         </styleClass>
      </JFXButton>
      <Separator prefWidth="200.0" />
      <JFXButton buttonType="RAISED" onAction="#addCarAction" prefHeight="50.0" prefWidth="199.0" style="-fx-background-color: #ff033e;" stylesheets="@style.css" text="ADD CAR" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <styleClass>
            <String fx:value="menu-btn" />
            <String fx:value="btn" />
         </styleClass>
      </JFXButton>
      <Separator prefWidth="200.0" />
      <JFXButton buttonType="RAISED" layoutX="10.0" layoutY="196.0" onAction="#listCarsAction" prefHeight="50.0" prefWidth="199.0" style="-fx-background-color: #ff033e;" stylesheets="@style.css" text="LIST CARS" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <styleClass>
            <String fx:value="menu-btn" />
            <String fx:value="btn" />
         </styleClass>
      </JFXButton>
      <Separator prefWidth="200.0" />
      <JFXButton buttonType="RAISED" layoutX="10.0" layoutY="196.0" onAction="#searchAction" prefHeight="50.0" prefWidth="199.0" style="-fx-background-color: #ff033e;" stylesheets="@style.css" text="SEARCH" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <styleClass>
            <String fx:value="menu-btn" />
            <String fx:value="btn" />
         </styleClass>
      </JFXButton>
      <TextFlow layoutX="10.0" layoutY="160.0" prefHeight="18.0" prefWidth="200.0" style="-fx-background-color: #f0f8ff;" styleClass="navigation" stylesheets="@style.css">
         <children>
            <Text strokeType="OUTSIDE" strokeWidth="0.0" text="MANAGER" wrappingWidth="176.49267578125" />
         </children>
      </TextFlow>
      <JFXButton buttonType="RAISED" layoutX="10.0" layoutY="196.0" onAction="#agentsAction" prefHeight="50.0" prefWidth="199.0" style="-fx-background-color: #ff033e;" stylesheets="@style.css" text="AGENTS" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <styleClass>
            <String fx:value="menu-btn" />
            <String fx:value="btn" />
         </styleClass>
      </JFXButton>
      <Separator prefWidth="200.0" />
      <JFXButton buttonType="RAISED" layoutX="10.0" layoutY="408.0" onAction="#profileAction" prefHeight="50.0" prefWidth="199.0" style="-fx-background-color: #ff033e;" stylesheets="@style.css" text="PROFILE" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <styleClass>
            <String fx:value="menu-btn" />
            <String fx:value="btn" />
         </styleClass>
      </JFXButton>
      <Separator prefWidth="200.0" />
      <JFXButton buttonType="RAISED" layoutX="10.0" layoutY="441.0" onAction="#logoutAction" prefHeight="50.0" prefWidth="199.0" style="-fx-background-color: #ff033e;" stylesheets="@style.css" text="LOGOUT" textFill="WHITE">
         <font>
            <Font size="16.0" />
         </font>
         <styleClass>
            <String fx:value="menu-btn" />
            <String fx:value="btn" />
         </styleClass>
      </JFXButton>
   </children>
</VBox>

The error occurs when I click on the logout button in DefaultContentController, the "Logout" message is displayed, but I don't understand that error. Help please. Thks.

当我单击 DefaultContentController 中的注销按钮时出现错误,显示“注销”消息,但我不明白该错误。请帮忙。谢谢。

采纳答案by James_D

You load and displayDrawerContent.fxmlin the initialize()method of RootLayoutController:

您在以下方法中加载和显示DrawerContent.fxmlinitialize()RootLayoutController

public class RootLayoutController {

    // Reference to the main application
    @SuppressWarnings("unused")
    private MainApp mainApp;

    // ...


    /**
     * Initializes the controller class.
     */
    @FXML
    private void initialize() {
        try {
            VBox box = FXMLLoader.load(getClass().getResource("DrawerContent.fxml"));
            drawer.setSidePane(box);

            // ...

        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Is called by the main application to give a reference back to itself
     * 
     * @param mainApp
     */
    public void setMainApp(MainApp mainApp) {
        this.mainApp = mainApp;
    }

}

Of course, this creates a new DrawerContentControllerlinked to the view created from DrawerContent.fxml. At no point do you call setMainApp(...)on that controller, so in that instance of DrawerContentController, mainAppis null. Consequently, when the user presses the LOGOUTbutton and invokes the handler method, you get a null pointer exception.

当然,这会创建一个新的DrawerContentController链接到从DrawerContent.fxml. 在任何时候你调用setMainApp(...)该控制器上,所以在该实例中DrawerContentControllermainApp为空。因此,当用户按下LOGOUT按钮并调用处理程序方法时,您会得到一个空指针异常。

You need to initialize the mainAppin the DrawerContentController. You can do that with:

您需要mainAppDrawerContentController. 你可以这样做:

import java.io.IOException;

import com.jfoenix.controls.JFXDrawer;
import com.jfoenix.controls.JFXHamburger;
import com.jfoenix.transitions.hamburger.HamburgerBasicCloseTransition;

import gn.kahere.car.manager.MainApp;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;

public class RootLayoutController {

    // Reference to the main application

    // @SuppressWarnings("unused") // hmm if it's unused, I probably don't need it...

    // private MainApp mainApp;

    private DrawerContentController drawerContentController ;

    @FXML
    private JFXHamburger hamburger;

    @FXML
    private JFXDrawer drawer;


    /**
     * Controller
     */
    public RootLayoutController() {

    }

    /**
     * Initializes the controller class.
     */
    @FXML
    private void initialize() {
        try {
            FXMLLoader drawerContentLoader = new FXMLLoader(getClass().getResource("DrawerContent.fxml"));
            VBox box = drawerContentLoader.load();
            drawer.setSidePane(box);

            drawerContentController = drawerContentLoader.getController();

            HamburgerBasicCloseTransition burgerTask = new HamburgerBasicCloseTransition(hamburger);
            burgerTask.setRate(-1);

            hamburger.addEventHandler(MouseEvent.MOUSE_PRESSED, (e) -> {
                burgerTask.setRate(burgerTask.getRate() * -1);
                burgerTask.play();

                if(drawer.isShown())
                    drawer.close();
                else
                    drawer.open();
            });
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Is called by the main application to give a reference back to itself
     * 
     * @param mainApp
     */
    public void setMainApp(MainApp mainApp) {
        // this.mainApp = mainApp;

        // pass the main app to the drawerContentController:
        drawerContentController.setMainApp(mainApp);
    }

}

Obviously, you can remove all the redundant code from your MainAppclass that loads FXML files and never displays their content (why would you do that anyway?):

显然,您可以从MainApp类中删除加载 FXML 文件并且从不显示其内容的所有冗余代码(为什么要这样做?):

public class MainApp extends Application {

    private Stage primaryStage;
    private AnchorPane rootLayout;

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("Car Manager");

        // Prevent the window resizing
        this.primaryStage.setResizable(false);

        showLogin();
    }

    /**
     * Show the login page
     */
    public void showLogin() {
        try {
            // Load login page
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("view/Login.fxml"));
            AnchorPane login = (AnchorPane) loader.load();

            // Set the scene containing the login page
            Scene scene = new Scene(login);
            primaryStage.setScene(scene);

            // Give the controller access to the main application
            LoginController controller = loader.getController();
            controller.setMainApp(this);

            // Show the scene
            primaryStage.show();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Initializes the root layout
     */
    public void initRootLayout() {
        try {
            // Load root layout
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
            rootLayout = (AnchorPane) loader.load();

            // Give the controller access to the main application
            RootLayoutController controller = loader.getController();
            controller.setMainApp(this);

            // Get the DrawerContentController 

            // really no point in doing that since you don't display the UI you load...
            // FXMLLoader drawerLoader = new FXMLLoader();
            // drawerLoader.setLocation(MainApp.class.getResource("view/DrawerContent.fxml"));
            // drawerLoader.load(); // Load the fxml file (and do nothing with it)
            // DrawerContentController drawerController = drawerLoader.getController();
            // drawerController.setMainApp(this);

            // Show the scene containing the root layout
            Scene scene = new Scene(rootLayout);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}