-1
我有一個JavaFX項目包含FXML文件及其控制器和主類Jar文件將無法運行後生成的神器 - JavaFX的
程序完美的作品在IDE「的IntelliJ」 但是當我嘗試製作工件並構建它時,jar文件就不會運行「當然安裝了JRE」
我嘗試了很多方法來構建工件,所以是否有構建jar文件的特定方法FXML文件?
堆棧跟蹤異常
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 sample.Main.start(Main.java:20)
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 sample.Main
主類含有這種 「FXML裝載機」
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
Parent root = null;
try {
root = FXMLLoader.load(getClass().getResource("/Sample/MainLayout.fxml"));
primaryStage.setTitle("Estimated Download Time");
primaryStage.setScene(new Scene(root, 764, 600));
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("Logo.png")));
primaryStage.resizableProperty().setValue(Boolean.FALSE);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {launch(args);}
}
「的jar文件就不會跑」。究竟發生了什麼?你有例外嗎?如果沒有,您是否嘗試過從命令行運行jar文件來查看它是否以這種方式生成堆棧跟蹤? –
我實際上得到java.lang.reflect.InvocationTargetException 例外在應用程序啓動方法 但程序完美地在IDE上運行! – AhmadMujahid
因此,在問題中發佈完整的堆棧跟蹤。 FXML文件的路徑可能不正確,或者FXML文件未被部署到jar文件。 –