javafx gui中的异常

时间:2019-03-31 09:43:25

标签: user-interface javafx netbeans-8

我试图在netbeans和场景构建器中使用javafx为学校项目创建UI,但是当我尝试运行该程序时,它在Application start方法中显示异常,有人可以解决该问题吗?

这是fxml代码     

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon?>
<?import javafx.scene.control.Label?>
<?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" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="451.0" prefWidth="754.0" style="-fx-background-color: #20120f;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/11.0.1" fx:controller="chatapp.FXMLDocumentController">
  <children>
  <ImageView fitHeight="451.0" fitWidth="754.0" opacity="0.51" pickOnBounds="true">
     <image>
        <Image url="@../images/arctic_wolf_winter_mountains_5k.jpg" />
     </image>
  </ImageView>
  <AnchorPane layoutX="416.0" layoutY="50.0" prefHeight="377.0" prefWidth="300.0" style="-fx-background-color: #9c2827;">
     <children>
        <JFXTextField focusColor="#030e75" labelFloat="true" layoutX="37.0" layoutY="90.0" prefHeight="25.0" prefWidth="227.0" promptText="Username/Email" unFocusColor="WHITE">
           <font>
              <Font size="14.0" />
           </font>
        </JFXTextField>
        <JFXPasswordField focusColor="#030e75" labelFloat="true" layoutX="37.0" layoutY="156.0" prefHeight="25.0" prefWidth="227.0" promptText="password" unFocusColor="WHITE">
           <font>
              <Font size="14.0" />
           </font>
        </JFXPasswordField>
        <JFXButton layoutX="37.0" layoutY="238.0" prefHeight="29.0" prefWidth="227.0" style="-fx-background-color: #e45652;" text="Sign In" textFill="WHITE" />
        <Label layoutX="121.0" layoutY="29.0" prefHeight="34.0" prefWidth="79.0" text="Sign In" textFill="#f2f2f2">
           <font>
              <Font size="24.0" />
           </font>
        </Label>
        <Label layoutX="111.0" layoutY="305.0" text="Forgot Password?" textFill="#eee8e8" underline="true">
           <font>
              <Font name="Times New Roman" size="13.0" />
           </font>
        </Label>
     </children>
  </AnchorPane>
  <Label layoutX="32.0" layoutY="136.0" text="Welcome to Chatbox" textFill="#f2eeee">
     <font>
        <Font name="System Bold" size="36.0" />
     </font>
  </Label>
  <Label layoutX="47.0" layoutY="205.0" text="A messenger app unlike any!!! Stay connected with your &#10;friends and loved ones through multiple social networks" textAlignment="JUSTIFY" textFill="#fff8f8" />
  <JFXButton layoutX="120.0" layoutY="249.0" prefHeight="29.0" prefWidth="180.0" style="-fx-background-color: #e45652;" text="Sign up" textFill="WHITE" />
  <Pane layoutX="611.0" layoutY="1.0" onMouseClicked="#handleclose" prefHeight="34.0" prefWidth="142.0">
     <children>
        <FontAwesomeIcon fill="#fcf8f8" iconName="CLOSE" layoutX="109.0" layoutY="22.0" onMouseClicked="#handleclose" size="1.5em" />
     </children>
  </Pane>
 </children>
</AnchorPane>

这是控制器

package chatapp;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;

public class FXMLDocumentController implements Initializable {

    @FXML
    private Label label;

    @FXML

    private void handleclose(ActionEvent event) {
       System.exit(0);
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    // TODO
    }    

   }

这是主要方法

package chatapp;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class Chatapp extends Application {

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
    stage.initStyle(StageStyle.UNDECORATED);
    Scene scene = new Scene(root);

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

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

}

最后这是控制台中显示的错误

ant -f C:\\Users\\Akotet\\Documents\\NetBeansProjects\\Chatapp jfxsa-run init: Deleting: C:\Users\Akotet\Documents\NetBeansProjects\Chatapp\build\built-jar.properties
deps-jar:
Updating property file:    C:\Users\Akotet\Documents\NetBeansProjects\Chatapp\build\built-jar.properties compile:
Deleting directory C:\Users\Akotet\Documents\NetBeansProjects\Chatapp\dist\lib
Copying 3 files to C:\Users\Akotet\Documents\NetBeansProjects\Chatapp\dist\lib
Detected JavaFX Ant API version 1.3
jfx-deployment:
jar:
Copying 15 files to C:\Users\Akotet\Documents\NetBeansProjects\Chatapp\dist\run930757708
jfx-project-run:
Executing C:\Users\Akotet\Documents\NetBeansProjects\Chatapp\dist\run930757708\Chatapp.jar using platform C:\Program Files\Java\jdk1.8.0_144\jre/bin/java
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$155(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:335)
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 chatapp.Chatapp.start(Chatapp.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
... 1 more
Exception running application chatapp.Chatapp
Java Result: 1
Deleting directory      C:\Users\Akotet\Documents\NetBeansProjects\Chatapp\dist\run930757708
jfxsa-run:
BUILD SUCCESSFUL (total time: 8 seconds)

0 个答案:

没有答案