主文件运行时FXML加载异常。文件路径正确,stll失败

时间:2019-06-08 20:31:11

标签: javafx netbeans scenebuilder

我将SceneBuilder与netbeans一起使用来创建一些场景。当我运行程序时,我不断收到此错误:

Caused by: java.lang.NullPointerException: Location is required.

我正在用正确的文件位置和软件包信息从主程序文件调用fxml文件。

我尝试使用绝对路径。我尝试将fxml移动到与主文件相同的包。我尝试删除fxml并重新开始。我尝试删除整个程序并重新开始。我有jfoenix-8.0.8 jar。 这是来自主文件

public class MacroCounter extends Application {

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

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }
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.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 main.MacroCounter.start(MacroCounter.java:22)
    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)
Exception running application main.MacroCounter
Java Result: 1

screen shot of packages in project

使用/scenes/FXMLDocument.fxml 我收到此错误:  造成原因:javafx.fxml.LoadException:文件:/Users/ryanhoffman/Desktop/School%20Work/Applied%20Software/MacroCounter/dist/run1913970246/MacroCounter.jar!/scenes/FXMLDocument.fxml:13 代替获取空指针 引起原因:java.lang.NullPointerException:必需的位置。

netbeans似乎正在移至文件所在的位置,但fxml无法正常工作。我认为它与此MacroCounter.jar有关!那是在文件路径中,但我真的不明白为什么。 MacroCounter.jar!/scenes/FXMLDocument.fxml:13

0 个答案:

没有答案