我想运行应用程序时出现Java FX错误

时间:2018-03-05 22:26:00

标签: java javafx netbeans-8 scenebuilder

我尝试使用javaFx构建一个Windows应用程序,当我尝试运行该应用程序时,它给了我这个。

ant -f D:\\java\\NetBeansProjects\\Login2 jfxsa-run init: Deleting:
 D:\java\NetBeansProjects\Login2\build\built-jar.properties deps-jar:
 Updating property file:
 D:\java\NetBeansProjects\Login2\build\built-jar.properties Compiling 1
 source file to D:\java\NetBeansProjects\Login2\build\classes compile:
 Deleting directory D:\java\NetBeansProjects\Login2\dist\lib Copying 1
 file to D:\java\NetBeansProjects\Login2\dist\lib Detected JavaFX Ant
 API version 1.3 Launching <fx:jar> task from D:\Program Files
 (x86)\Java\jdk1.8.0_161\jre\..\lib\ant-javafx.jar
 Warning: From JDK7u25 the Codebase manifest attribute should be used to restrict JAR repurposing.
          Please set manifest.custom.codebase property to override the current default non-secure value '*'. Launching <fx:deploy> task from
 D:\Program Files (x86)\Java\jdk1.8.0_161\jre\..\lib\ant-javafx.jar No
 base JDK. Package will use system JRE. No base JDK. Package will use
 system JRE. jfx-deployment-script: jfx-deployment: jar: Copying 13
 files to D:\java\NetBeansProjects\Login2\dist\run1325232323
 jfx-project-run: Executing
 D:\java\NetBeansProjects\Login2\dist\run1325232323\Login2.jar using
 platform D:\Program Files (x86)\Java\jdk1.8.0_161\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$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
 Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
    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 login2.Login2.start(Login2.java:22)
    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 login2.Login2 Java Result: 1
 Deleting directory D:\java\NetBeansProjects\Login2\dist\run1325232323
 jfxsa-run: BUILD SUCCESSFUL (total time: 4 seconds)

FXMLDocumentController.java:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package login2;

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;

/**
 *
 * @author IULIAN-DANIELGLAVAN
 */
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

    }    


}

Login.java:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package login2;

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

/**
 *
 * @author IULIAN-DANIELGLAVAN
 */
public class Login2 extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/FXMLDocument.fxml"));


        Scene scene = new Scene(root);

        stage.setScene(scene);
        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.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" prefHeight="271.0" prefWidth="610.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/9.0.1" fx:controller="login2.FXMLDocumentController">
   <children>
      <JFXTextField layoutX="191.0" layoutY="94.0" prefHeight="30.0" prefWidth="235.0" promptText="Email" />
      <JFXPasswordField layoutX="191.0" layoutY="144.0" prefHeight="25.0" prefWidth="235.0" promptText="Password" />
      <JFXButton layoutX="511.0" layoutY="35.0" onMouseClicked="#handleClose" text="x">
         <font>
            <Font size="14.0" />
         </font>
      </JFXButton>
   </children>
</AnchorPane>

我将jfoenix.jar放在库中。

0 个答案:

没有答案