应用程序启动方法java.lang.reflect.InvocationTargetException中的JavaFX异常

时间:2018-07-19 01:50:57

标签: javafx

你好,我是Java的新手,我在运行此GUI时遇到了一些麻烦,我在stackoverflow上搜索了该解决方案,但到目前为止对我来说都没有用,似乎我的所有文件都在正确的位置并且在FXML文档中被正确指向。

JavaFX_SettingsBar.java

    package javafx_settingsbar;

    import java.awt.Color;
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.fxml.FXMLLoader;
    import javafx.geometry.Rectangle2D;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.input.MouseEvent;
    import javafx.stage.Screen;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;

    /**
     *
     * @author proxc
     */
    public class JavaFX_SettingsBar extends Application {
        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.TRANSPARENT);
                 root.setOnMousePressed((MouseEvent event) -> {
                     xOffset = event.getSceneX();
                     yOffset = event.getSceneY();
            });
            root.setOnMouseDragged(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                    stage.setX(event.getScreenX() - xOffset);
                    stage.setY(event.getScreenY() - yOffset);
                }
            });
            Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
        
            Scene scene = new Scene(root);
            scene.setFill(javafx.scene.paint.Color.TRANSPARENT);
            stage.setScene(scene);
         
    //set Stage boundaries to the lower right corner of the visible bounds of the main screen
    stage.setX(primaryScreenBounds.getMinX() + primaryScreenBounds.getWidth() - 385); //framesize -15
    stage.setY(primaryScreenBounds.getMinY() + primaryScreenBounds.getHeight() - 471); //framesize +5
    stage.setWidth(370);
    stage.setHeight(466);
            stage.show();
        }

        /**
         * @param args the command line arguments
         */
        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.JFXCheckBox?>
<?import com.jfoenix.controls.JFXSlider?>
<?import com.jfoenix.controls.JFXToggleButton?>
<?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.text.Font?>

<AnchorPane id="AnchorPane" fx:id="root" prefHeight="466.0" prefWidth="370.0" style="-fx-background-color: rgba(0, 100, 100, 0);" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafx_settingsbar.FXMLDocumentController">
   <children>
      <AnchorPane fx:id="topbar" prefHeight="73.0" prefWidth="380.0" style="-fx-background-color: #3D4956;">
         <children>
            <ImageView fx:id="btn_settings" layoutX="49.0" layoutY="21.0" onMousePressed="#handleButtonAction" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/settings.png" />
               </image>
            </ImageView>
            <ImageView fx:id="btn_user" layoutX="130.0" layoutY="25.0" onMousePressed="#handleButtonAction" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/user.png" />
               </image>
            </ImageView>
            <ImageView layoutX="218.0" layoutY="25.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/awards.png" />
               </image>
            </ImageView>
            <ImageView fx:id="btn_exit" layoutX="304.0" layoutY="28.0" onMousePressed="#handleButtonAction" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/shutdown.png" />
               </image>
            </ImageView>
         </children>
      </AnchorPane>
      <AnchorPane fx:id="h_settings" layoutY="88.0" prefHeight="374.0" prefWidth="380.0" style="-fx-background-color: #3D4956;" visible="false">
         <children>
            <Label layoutX="33.0" layoutY="32.0" text="TOUCH ENABLED" textFill="WHITE">
               <font>
                  <Font name="System Bold" size="12.0" />
               </font>
            </Label>
            <JFXToggleButton layoutX="242.0" layoutY="21.0" prefHeight="56.0" prefWidth="93.0" text="On" textFill="#eda678" toggleColor="#eda678" toggleLineColor="#eba478e2" />
            <Label layoutX="33.0" layoutY="61.0" text="Called 3D Touch, the new &#10;technology can sense pressure &#10;" textFill="#f2efef">
               <font>
                  <Font size="9.0" />
               </font>
            </Label>
            <Label layoutX="33.0" layoutY="104.0" text="AUTO-SUBSCRIBE" textFill="WHITE">
               <font>
                  <Font name="System Bold" size="12.0" />
               </font>
            </Label>
            <JFXToggleButton layoutX="242.0" layoutY="93.0" prefHeight="56.0" prefWidth="93.0" text="On" textFill="#eda678" toggleColor="#eda678" toggleLineColor="#eba478e2" />
            <Label layoutX="33.0" layoutY="126.0" text="Auto subsribe to the channel" textFill="#f2efef">
               <font>
                  <Font size="9.0" />
               </font>
            </Label>
            <Separator layoutX="35.0" layoutY="188.0" opacity="0.33" prefHeight="1.0" prefWidth="307.0" />
            <JFXSlider layoutX="35.0" layoutY="252.0" prefHeight="14.0" prefWidth="307.0" snapToTicks="true" />
            <Label layoutX="40.0" layoutY="206.0" text="SCREEN BRIGHTNESS" textFill="WHITE">
               <font>
                  <Font name="System Bold" size="12.0" />
               </font>
            </Label>
            <JFXCheckBox checkedColor="#eda678" layoutX="33.0" layoutY="280.0" text="Auto Brightness" textFill="#fffdfd" />
            <JFXButton layoutX="217.0" layoutY="318.0" prefHeight="25.0" prefWidth="125.0" style="-fx-background-color: #eda678; -fx-border-radius: 5em; -fx-background-radius: 5em;" text="Save" />
            <JFXButton layoutX="47.0" layoutY="318.0" prefHeight="25.0" prefWidth="125.0" style="-fx-background-color: #515D6D; -fx-border-radius: 5em; -fx-background-radius: 5em;" text="Cancel" textFill="WHITE" />
            <ImageView layoutX="56.0" layoutY="-13.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/up.png" />
               </image>
            </ImageView>
         </children>
      </AnchorPane>
      <AnchorPane fx:id="h_user" layoutY="87.0" prefHeight="381.0" prefWidth="380.0" style="-fx-background-color: #3D4956;" visible="false">
         <children>
            <ImageView layoutX="161.0" layoutY="80.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/user_male.png" />
               </image>
            </ImageView>
            <Label layoutX="170.0" layoutY="167.0" text="Amos C" textFill="WHITE">
               <font>
                  <Font name="System Bold" size="12.0" />
               </font>
            </Label>
            <Label layoutX="153.0" layoutY="191.0" text="UI/UX Designer" textFill="WHITE">
               <font>
                  <Font size="11.0" />
               </font>
            </Label>
            <ImageView layoutX="134.0" layoutY="-12.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@images/up.png" />
               </image>
            </ImageView>
         </children></AnchorPane>
   </children>
</AnchorPane>

跟踪

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.UnsupportedClassVersionError: com/jfoenix/controls/JFXButton has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2916)
	at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2905)
	at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2846)
	at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2692)
	at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2661)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
	at javafx_settingsbar.JavaFX_SettingsBar.start(JavaFX_SettingsBar.java:29)
	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
Exception running application javafx_settingsbar.JavaFX_SettingsBar
Java Result: 1

0 个答案:

没有答案