应用程序启动方法java.lang.reflect.InvocationTargetException中的Javafx错误Exception

时间:2018-10-09 15:52:31

标签: java javafx jfoenix

我的java文件:

package Test_Java;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class JavaFX_BasicDetails extends Application {

    // init xy offsets
    private double xOffset = 0;
    private double yOffset = 0;

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
        stage.initStyle(StageStyle.UNDECORATED);
        // make it movable
        // set on mousepress /drag

        // set mouse pressed
        root.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                xOffset = event.getSceneX();
                yOffset = event.getSceneY();
            }
        });
        // set mouse drag
        root.setOnMouseDragged(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                stage.setX(event.getScreenX() - xOffset);
                stage.setY(event.getScreenY() - yOffset);
            }
        });

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }

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

}

我的FXMLDocument.fxml文件:

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

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXComboBox?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" prefHeight="417.0" prefWidth="700.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.111" fx:controller="javafx_basicdetails.FXMLDocumentController">
   <children>
      <Pane prefHeight="417.0" prefWidth="110.0" style="-fx-background-color: #48A5EA;">
         <children>
            <ImageView fitHeight="25.0" fitWidth="21.0" layoutX="45.0" layoutY="37.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/up_1.png" />
               </image>
            </ImageView>
            <ImageView fitHeight="21.0" fitWidth="21.0" layoutX="45.0" layoutY="363.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/down_1.png" />
               </image>
            </ImageView>
            <ImageView fitHeight="25.0" fitWidth="21.0" layoutX="45.0" layoutY="198.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/exercise_24px.png" />
               </image>
            </ImageView>
         </children>
      </Pane>
      <JFXTextField focusColor="#48a5ea" layoutX="133.0" layoutY="92.0" prefHeight="25.0" prefWidth="217.0" promptText="First Name" />
      <JFXTextField focusColor="#48a5ea" layoutX="133.0" layoutY="157.0" prefHeight="25.0" prefWidth="217.0" promptText="Email ID" />
      <JFXTextField focusColor="#48a5ea" layoutX="133.0" layoutY="283.0" prefHeight="25.0" prefWidth="217.0" promptText="Phone Number" />
      <JFXTextField focusColor="#48a5ea" layoutX="418.0" layoutY="92.0" prefHeight="25.0" prefWidth="217.0" promptText="Last Name" />
      <JFXTextField focusColor="#48a5ea" layoutX="418.0" layoutY="157.0" prefHeight="25.0" prefWidth="217.0" promptText="Your User ID" />
      <JFXTextField focusColor="#48a5ea" layoutX="412.0" layoutY="283.0" prefHeight="25.0" prefWidth="217.0" promptText="Reference Code" />
      <Label layoutX="133.0" layoutY="31.0" text="Basic Details" textFill="#48a5ea">
         <font>
            <Font name="System Bold" size="16.0" />
         </font>
      </Label>
      <JFXComboBox focusColor="#48a5ea" layoutX="133.0" layoutY="224.0" prefHeight="25.0" prefWidth="217.0" promptText="Country" />
      <JFXComboBox focusColor="#48a5ea" layoutX="415.0" layoutY="224.0" prefHeight="25.0" prefWidth="94.0" promptText="State" />
      <JFXComboBox focusColor="#48a5ea" layoutX="535.0" layoutY="224.0" prefHeight="25.0" prefWidth="94.0" promptText="City" />
      <JFXButton layoutX="133.0" layoutY="349.0" prefHeight="25.0" prefWidth="94.0" text="Reset All" />
      <JFXButton layoutX="524.0" layoutY="349.0" prefHeight="25.0" prefWidth="116.0" style="-fx-background-color: #48A5EA;" text="Continue" textFill="WHITE" />
      <Separator layoutX="133.0" layoutY="68.0" prefHeight="1.0" prefWidth="520.0" />
      <Label id="btn_exit" fx:id="btn_exit" layoutX="675.0" layoutY="2.0" onMousePressed="#handleButtonAction" prefHeight="25.0" prefWidth="21.0" text="X" textFill="#48a5ea">
         <font>
            <Font name="System Bold" size="16.0" />
         </font>
      </Label>
   </children>
</AnchorPane>

启动应用程序时,我收到以下输出:

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:564)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
    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:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:941)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: javafx.fxml.LoadException: 
/repo/Test_Java/FXMLDocument.fxml:14
    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:930)
    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:3253)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
    at SetonHallCSS_Java.JavaFX_BasicDetails.start(JavaFX_BasicDetails.java:29)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)

我的Java文件假设要启动一个使用javafx和jfoenix的java gui。我已将.getResource()替换为fxml文件的目录和文件,并已将其替换为“ /my.fxml”,但仍会产生相同的输出。

0 个答案:

没有答案