当前位置: 首页 > 知识库问答 >
问题:

cmd中的JavaFX FXMLLoader异常

阳俊德
2023-03-14

我正在开发一个使用JavaFXUI的mp3播放器。当我在NetBeans中启动应用程序时,它运行良好。但是当我用Clean和Build创建一个可执行jar并用cmd启动它时,我得到一个异常,FXMLLoader加载fxml文件。

路径一定有问题吧?

第一个项目结构

项目结构

我创建了第二个应用程序,并将所有内容存储在一个文件夹中。创建了一个可执行的jar,它运行良好。

第二个项目结构

项目结构

源代码(第一)

package jornsfx;

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

public class JornsFX extends Application{

    @Override
    public void start(Stage stage)throws Exception{
        stage.setResizable(false);
        Parent root = FXMLLoader.load(getClass().getResource("/views/jornsFX.fxml")); 
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("JornsFX");
        stage.show();
    }

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

例外(第一)

Exception in Application start method
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        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(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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(Unknown Source)
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 jornsfx.JornsFX.start(JornsFX.java:14)
        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 jornsfx.JornsFX

共有1个答案

萧光华
2023-03-14

我不能肯定地告诉你,但看起来

getClass().getResource("/views/jornsFX.fxml")

在你的start()方法是null异常提示它,并且该文件在屏幕截图中被命名为/view/JornsFX. fxml

 类似资料:
  • 我想从cmd执行一个基于spring的jar文件。 这是我的pom。xml: 我在intelliJ中创建了一个jar文件,它运行正常,但当我这样做时:java-jar fileserver-1.0-SNAPSHOT. jar 我得到:异常在线程"主"java.lang.NoClassDefFoundError: org/springFramework/引导/SpringApplication 编辑

  • 我有一个容器在其入口点中使用卷。例如: 我将它移到了compose,但只有当我的compose指向部分中的Dockerfile时,它才会起作用,如果我试图在部分中写入相同的行,则没有按照我的预期操作,并抛出file not found错误。 我还尝试使用,这给了我同样的错误。 问题是--为什么在执行docker-compose“命令”时我没有这个卷?有没有办法使这个工作/重写我的dockerfil

  • cmd

    cmd usage_audit.py,检测存在哪些网络资源(包括网络、子网、端口、路由器和浮动IP),显示它们的信息。 sanity_check.py,进行一些简单的检查,包括是否支持vxlan,是否支持patch端口,是否支持nova的notify等。

  • 我的问题是,当我编写以下命令时: 我看到了cmd本身的不同之处,而不是启动vscode进行编辑和合并。 这里有什么问题?为什么不启动可视代码? 但同样的问题。

  • 我在从命令提示符编译java时遇到了一个问题。起初,它说javac不是一个公认的内部或外部命令,通过阅读,我看到您需要更改路径,这正是我所做的······ 变量名:path 我关闭了Compand prompt并再次尝试,但还是出现了同样的问题。 然后我尝试了echo%path%和整个路径行被回显(整个行根据该变量值) 我还尝试了“for%I in(javac.exe)do@ECHO%~$path

  • 主页: Cmd Markdown 平台: Windows OSX Linux Web 费用: 免费 技术: Web 介绍 Cmd Markdown 是一款使用 Web 技术开发的,全面且强大的 Markdown 编辑器。它拥有实时预览、离线编辑、智能同步、发布共享等功能,并提供了 Web 版和 Windows、OSX、Linux 平台的客户端,体验很棒。 截图