Matthias Brück Matthias Brück - 5 months ago 45x
Java Question

JavaFX Error with Netbeans Standard FXML application - Nullpointer for .fxml file

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(
at com.sun.javafx.application.LauncherImpl.access$000(
at com.sun.javafx.application.LauncherImpl$
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.load(
at javafx.fxml.FXMLLoader.load(
at javafx.fxml.FXMLLoader.load(
at javafx.fxml.FXMLLoader.load(
at javafx.fxml.FXMLLoader.load(
at volltextsuche.Volltextsuche.start(

This is my start() method:

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);

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

IDE with project


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.