Issue
When I create a new Netbeans Projekt (JavaFX FXML Application) with application class I receive a template as usual (one .fxml, one controller class and the main application). When I try to run this I get an exception:
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2825)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771)
at volltextsuche.Volltextsuche.start(Volltextsuche.java:25)
[...]
This is my start() method:
@Override
public void start(Stage stage) throws Exception {
URL url = getClass().getResource("FXMLDocument.fxml");
System.out.println(url == null);
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
and somehow the URL is null. Line 25 is the Parent root = [...]
part. The .fxml document has the exact same name as the Strings tell and is in the same package as the main application class. I didn't change anything, just the null check for the URL. I googled for a long time, but I couldn't find anything regarding this error.
- JDK 8.0_45
- Netbeans 8.0.2
- Win 8.1 x64
Solution
Ok, I found the error, see here. The error is differnent but the solution is the same. I found a broken reference to dist.jar in my project settings. As the answered question in the link states I had to CLEAN and build
the project for the first build. The broken reference got fixed by that. I deleted all already compiled files and now the compiler does everything needed and compiles the whole project.
Answered By - Matthias Brück