2017-07-28 62 views
0

我書面方式在Java程序,我使用JavaFX的GUI。直到今天,我已經獨自使用javafx stand代碼,並且一切運行順利。 我決定開始使用Maven和目前該項目犯規編譯也不運行或執行。JavaFX項目與Maven編譯,但犯規執行

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.java.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 main.java.Main 

這是我的主類:其他項目

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

@Override 
public void start(Stage primaryStage) throws Exception { 
    Parent root = FXMLLoader.load(getClass().getResource("../fxml/AuthenticationForm.fxml")); 
    primaryStage.setTitle("Gym Master 1000"); 
    primaryStage.setScene(new Scene(root)); 
    primaryStage.show(); 
    primaryStage.setResizable(false); 
    primaryStage.centerOnScreen(); 

    root.getChildrenUnmodifiable(); 
} 

我已經使用Maven的,但從來沒有使用JavaFX。我該怎麼辦?

+0

見https://stackoverflow.com/questions/34755630/javafx-location-is-not-set-error當你打包成JAR文件,你不應該在資源名稱中使用'..'。 –

回答

0

首先確保您的.fxml文件與主類位於同一目錄中,並使用.getResource("complete path")中的完整路徑,而不是getResource("../fxml/AuthenticationForm.fxml")),因爲..無效。

您也可以使用:

相反:

Parent root = FXMLLoader.load(getClass().getResource("../fxml/AuthenticationForm.fxml")); 

欲瞭解更多信息,你可以看看herehere。 感謝James_D從他的信息。

+1

['..'不是一個有效的資源名稱(https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html),所以我不認爲這將解決它。 –

+0

經過一番研究,你是對的,「../fxml/AuthenticationForm.fxml」不是一個有效的名稱,我將編輯我的問題immediately.Thanks。 –

相關問題