JavaFX:线程“JavaFX应用程序线程”中的异常java.lang.RuntimeException:java.lang.reflect.InvocationTargetException [英] JavaFX: Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

查看:4297
本文介绍了JavaFX:线程“JavaFX应用程序线程”中的异常java.lang.RuntimeException:java.lang.reflect.InvocationTargetException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究JavaFX项目,我有这样的错误:

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

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$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.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: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$handleMouseEvent$354(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$49(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

我的MainApp.java

My MainApp.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

My 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

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

DrawerContentController.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

DrawerContent.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>

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

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.

推荐答案

您加载并显示 DrawerContent.fxml 的初始化()方法 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;
    }

}

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

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

您需要在 DrawerContentController 中初始化 mainApp 。你可以这样做:

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

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);
    }

}

显然,你可以删除全部来自 MainApp 类的冗余代码,它加载FXML文件并且从不显示它们的内容(为什么还要这样做?):

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

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);
    }
}

这篇关于JavaFX:线程“JavaFX应用程序线程”中的异常java.lang.RuntimeException:java.lang.reflect.InvocationTargetException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆