JavaFX FXMLLoader仅在JAR文件中“位置是必需的”

时间:2018-04-09 13:22:13

标签: java javafx fxml

我有一个工作的JavaFX应用程序,它运行在Intellij中。但是,我正在尝试将应用程序作为Jar文件运行,但是我得到一个NullPointerException,说明该位置是必需的。

我已经查看了有关此问题的每个主题,但没有一个解决方案似乎有效。

错误讯息:

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 systems.biology.laboratory.Main.initialSetup(Main.java:23)
at systems.biology.laboratory.Main.start(Main.java:19)
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 systems.biology.laboratory.Main

目录片段:

enter image description here

这是我用来调用FXMLLoader的方法

    private void initialSetup(Stage primaryStage) throws java.io.IOException {
    Parent root = FXMLLoader.load(getClass().getResource("/fxml/comparisonViewer.fxml"));
    //Parent root = loader.load();
    primaryStage.setTitle("Peak Viewer");
    scene = new Scene(root, 1500, 850);
    primaryStage.setMaximized(true);

    //scene.getStylesheets().add("/static/css/bootstrap3.css");
    primaryStage.setScene(scene);
    primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/static/images/peak.png")));
    primaryStage.show();
    controller = new ViewerController();
    controller.setStage(primaryStage);
}

因为它在intellij中工作正常,但不在jar中。我需要指定其他内容吗?

0 个答案:

没有答案