应用程序启动方法/位置中的JavaFX异常不需要修复 [英] JavaFX Exception in Application start method / Location is required no fix

查看:68
本文介绍了应用程序启动方法/位置中的JavaFX异常不需要修复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试了一系列课程/教程后,我试图在JavaFX中创建一个图书馆管理系统,并且遇到了以下问题:java.lang.RuntimeException:应用程序启动方法&中的异常;java.lang.NullPointerException:必须提供位置.

I am trying to create a library management system in JavaFX after a set of courses/tutorials and I reached these problems: java.lang.RuntimeException: Exception in Application start method & java.lang.NullPointerException: Location is required.

我已经检查了很多有关这两个特定问题的主题,似乎没有任何帮助.我正在使用SceneBuilder 9.0.1/Java 8.0/NetBeans 8.2.

I've checked lots of topics on these 2 particular problems and seems like nothing helped. I am using SceneBuilder 9.0.1 / Java 8.0 / NetBeans 8.2.

请紧记:我是java/javaFX的新手,在尝试学习这些主题时,我正在尝试完成一项作业.帮助将不胜感激.

Keep in mind: I am a rookie in java/javaFX and I'm trying to get an assignment done while learning on these topics. Help would be much appreciated.

这是代码:

package bibliotecajfx.ui.adaugacarte;

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

/**
 *
 * @author Munteanu Mihail
 */
public class BibliotecaJFX 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);
    }

}

也是FXMLController的副本:

Also a copy of the FXMLController:

package bibliotecajfx.ui.adaugacarte;

import bibliotecajfx.*;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextField;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

/**
 *
 * @author Munteanu Mihail
 */
public class FXMLDocumentController implements Initializable {

    private Label label;
    @FXML
    private JFXTextField title;
    @FXML
    private JFXTextField id;
    @FXML
    private JFXTextField editura;
    @FXML
    private JFXTextField autor;
    @FXML
    private JFXButton saveButton;
    @FXML
    private JFXButton cancelButton;

    DatabaseHandler databaseHandler;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        databaseHandler = new DatabaseHandler();
    }    

    @FXML
    private void addBook(ActionEvent event) {
    }

    @FXML
    private void cancel(ActionEvent event) {
    }

}

以及数据库代码:

package bibliotecajfx.database;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//import jdk.nashorn.internal.ir.Statement;

/**
 *
 * @author Munteanu Mihail
 */
public class DatabaseHandler {
    private static DatabaseHandler handler;

    private static final String DB_URL = "jdbc:derby:database;create:true";
    private static Connection conn = null;
    private static Statement stat = null;

    public DatabaseHandler(){
        createConnection();
        setupBookTable();
    }

    void createConnection(){
        try{
            Class.forName("org.apache.derby.jdbc.EnableDriver").newInstance();
            conn = DriverManager.getConnection(DB_URL);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    void setupBookTable(){
        String TABLE_NAME= "CARTE";
        try{
            stat = conn.createStatement();
            DatabaseMetaData dbm = conn.getMetaData();
            ResultSet tables = dbm.getTables(null, null, TABLE_NAME.toUpperCase(), null);
            if(tables.next()){
                System.out.println("Tabela"+TABLE_NAME+"exista deja!");
            }else{
                stat.execute("TABELA CREATA "+TABLE_NAME+"("
                +"      id varchar(200) primary key, \n"
                +"      titlu varchar(200), \n"
                +"      autor varchar(200),\n"
                +"      editura varchar(100),\n"
               // +"      intcode varchar(100),\n"
                +"      isAvail boolean defaul true"
                +" )");
            }
        }catch(SQLException e){
            System.err.println(e.getMessage()+" === init Database");
        }finally{

        }
    }
}

和日志:

ant -f "C:\\Users\\Munteanu Mihail\\Desktop\\bibliotecaJFX" -Djavafx.main.class=bibliotecajfx.ui.adaugacarte.BibliotecaJFX jfxsa-run
init:
deps-clean:
Updating property file: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\built-clean.properties
Deleting directory C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build
clean:
init:
deps-jar:
Created dir: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build
Updating property file: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\built-jar.properties
Created dir: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\classes
Created dir: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\empty
Created dir: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\generated-sources\ap-source-output
Compiling 4 source files to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\classes
warning: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\jfoenix-9.0.0.jar(com/jfoenix/controls/JFXButton.class): major version 53 is newer than 52, the highest major version supported by this compiler.
  It is recommended that the compiler be upgraded.
warning: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\jfoenix-9.0.0.jar(com/jfoenix/controls/JFXTextField.class): major version 53 is newer than 52, the highest major version supported by this compiler.
  It is recommended that the compiler be upgraded.
2 warnings
Copying 2 files to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\classes
compile:
Created dir: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist
Copying 3 files to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\lib
Detected JavaFX Ant API version 1.3
Going to create default keystore in C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\nb-jfx.jks
Generating Key for nb-jfx

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\nb-jfx.jks -destkeystore C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\build\nb-jfx.jks -deststoretype pkcs12".
Launching <fx:jar> task from C:\Program Files\Java\jdk1.8.0_152\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 '*'.
Signing JAR: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\bibliotecaJFX.jar to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\bibliotecaJFX.jar as nb-jfx
jar signed.

Warning: 
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2018-04-12) or after any future revocation date.
Enter Passphrase for keystore: Enter key password for nb-jfx: 
Signing JAR: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\lib\derby.jar to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\lib\derby.jar as nb-jfx
jar signed.

Warning: 
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2018-04-12) or after any future revocation date.
Enter Passphrase for keystore: Enter key password for nb-jfx: 
Signing JAR: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\lib\derbyclient.jar to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\lib\derbyclient.jar as nb-jfx
jar signed.

Warning: 
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2018-04-12) or after any future revocation date.
Enter Passphrase for keystore: Enter key password for nb-jfx: 
Signing JAR: C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\lib\jfoenix-9.0.0.jar to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\lib\jfoenix-9.0.0.jar as nb-jfx
jar signed.

Warning: 
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2018-04-12) or after any future revocation date.
Enter Passphrase for keystore: Enter key password for nb-jfx: 
Launching <fx:deploy> task from C:\Program Files\Java\jdk1.8.0_152\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 15 files to C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\run1897499086
jfx-project-run:
Executing C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\run1897499086\bibliotecaJFX.jar using platform C:\Program Files\Java\jdk1.8.0_152\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.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:338)
    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 bibliotecajfx.ui.adaugacarte.BibliotecaJFX.start(BibliotecaJFX.java:23)
    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 bibliotecajfx.ui.adaugacarte.BibliotecaJFX
Java Result: 1
Deleting directory C:\Users\Munteanu Mihail\Desktop\bibliotecaJFX\dist\run1897499086
jfxsa-run:
BUILD SUCCESSFUL (total time: 20 seconds)

项目布局:

推荐答案

首先,我要说FXML文件的路径错误.根据您的项目布局,应该是

First of all I´d say that the path to your FXML file is wrong. According to your project layout, it should be

Parent root = FXMLLoader.load(getClass().getResource("/bibliotecajfx/ui/adaugacarte/FXMLDocument.fxml"));

因为那是您的Java包树.开头的/表示该路径是从jar文件根目录开始的绝对路径.

because thats your java package tree. The / at the beginning indicates that the path is starting absolute from the jar file root.

此外,您正在使用的JFoenix库已经使用Java的较新版本进行了编译,因此您应该对其进行更新.或至少确保JFoenix的版本和Java的版本相同.

Also, the JFoenix library you´re using has been compiled with a newer version of Java, so you should update yours. or make sure that the verion of JFoenix and your Java verion are the same, at least.

欢呼

这篇关于应用程序启动方法/位置中的JavaFX异常不需要修复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆