java.lang.reflect.InvocationTargetException javafx.fxml.LoadException:

时间:2019-09-29 15:06:41

标签: java javafx

我的javafx项目遇到问题,希望有人可以帮助我。 我在Windows系统上使用openjdk12。我认为不确定fxml装入器的剂量。t work properly but I。 但是经过2个小时的Google研究,我没有找到任何解决方案。

该javafx正常工作,我导入了以下软件包:

C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx-swt.jar
C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx.base.jar
C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx.controls.jar
C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx.fxml.jar
C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx.graphics.jar
C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx.media.jar
C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx.swing.jar
C:\Program Files (x86)\jdk-12.0.2\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib\javafx.web.jar

并将此语句添加到VM选项: --module-path $ {PATH_TO_FX} --add-modules = javafx.controls,javafx.fxml

整个错误消息:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: javafx.fxml.LoadException: 
/C:/Users/Patrick%20PC/Desktop/Programmierung/Java/TimeManagmentProgramm/out/production/TimeManagmentProgramm/sample/menu/menu.fxml:9

    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
    at javafx.fxml/javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:105)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:941)
    at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
    at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
    at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
    at sample.menu.MenuView.<init>(MenuView.java:18)
    at sample.menu.MenuVC.<init>(MenuVC.java:25)
    at sample.Main.start(Main.java:23)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Caused by: java.lang.InstantiationException: sample.menu.MenuVC
    at java.base/java.lang.Class.newInstance(Class.java:584)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:936)
    ... 24 more
Caused by: java.lang.NoSuchMethodException: sample.menu.MenuVC.<init>()
    at java.base/java.lang.Class.getConstructor0(Class.java:3354)
    at java.base/java.lang.Class.newInstance(Class.java:571)
    ... 25 more
Exception running application sample.Main

Process finished with exit code 1

fxml文件

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.menu.MenuVC">
   <children>
      <Label alignment="CENTER" prefHeight="110.0" prefWidth="180.0" text="Menü">
         <VBox.margin>
            <Insets left="410.0" top="100.0" />
         </VBox.margin>
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
         <font>
            <Font size="48.0" />
         </font>
      </Label>
      <Button fx:id="zeiterfassung_Button" alignment="CENTER" mnemonicParsing="false" onAction="#zeiterfassung" prefHeight="60.0" prefWidth="200.0" text="Zeiterfassung">
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
         <VBox.margin>
            <Insets left="400.0" top="50.0" />
         </VBox.margin>
         <font>
            <Font size="24.0" />
         </font>
      </Button>
      <Button fx:id="projekte_Button" mnemonicParsing="false" onAction="#projekte" prefHeight="60.0" prefWidth="200.0" text="Projekte">
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
         <VBox.margin>
            <Insets left="400.0" top="50.0" />
         </VBox.margin>
         <font>
            <Font size="24.0" />
         </font>
      </Button>
      <Button fx:id="zielereichung_Button" mnemonicParsing="false" onAction="#zielereichung" prefHeight="60.0" prefWidth="200.0" text="Zielereichung">
         <font>
            <Font size="24.0" />
         </font>
         <VBox.margin>
            <Insets left="400.0" top="50.0" />
         </VBox.margin>
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
      </Button>
   </children>
</VBox>

模型

package sample.menu;

import javafx.stage.Stage;

public class MenuDataBean {

    private Stage primaryStage;

    public MenuDataBean(Stage primaryStage){
        this.primaryStage = primaryStage;
    }

    public Stage getPrimaryStage(){
        return primaryStage;
    }

}

控制器

package sample.menu;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;


public class MenuVC {

    //Model
    private MenuDataBean menuData;

    //View
    private MenuView view;

    public MenuVC(MenuDataBean menuData) throws IOException {
        this.menuData = menuData;
        view = new MenuView();
    }

    public void show(){
        view.show(menuData.getPrimaryStage());
    }

    @FXML
    private void zeiterfassung() throws IOException {}

    @FXML
    private void projekte(){
    }

    @FXML
    private void zielereichung(){
    }

}

视图

package sample.menu;

import com.sun.glass.ui.Menu;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.FileInputStream;
import java.io.IOException;

public class MenuView {

    private Scene scene;

    public MenuView() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("menu.fxml"));
        scene = new Scene(root, 1000, 800);
    }

    public void show(Stage stage){
        stage.setTitle("Menu");
        stage.setScene(scene);
        stage.show();
    }

}

主要

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import sample.menu.MenuDataBean;
import sample.menu.MenuVC;


public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{

        MenuDataBean menuData = new MenuDataBean(primaryStage);

        MenuVC menu = new MenuVC(menuData);
        menu.show();
    }


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

0 个答案:

没有答案