1

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

IDE with project

7
  • Is the FXML file in the same package as the Application class whose code you showed? Commented May 6, 2015 at 17:23
  • Yes it is. Sadly the URL is instantly null and I'm not able to print the path... Commented May 6, 2015 at 17:28
  • Can you see if the FXML is deployed along with the class files to wherever it is that Netbeans deploys its class files? (I'm not a NetBeans user, but I understand that sometimes it needs coercing to deploy resources other than class files from the source folders.) Commented May 6, 2015 at 17:40
  • Good hint, for some reason the log says Compiling 1 source file to D:\NetbeansProjects\Volltextsuche\build\classes and just the main application file got compiled. Not even the controller class. But I really have no clue why. Commented May 6, 2015 at 17:44
  • I compiled the controller manually, but the error stays the same (I can't compile the .fxml). Commented May 6, 2015 at 17:46

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

This is sort of a temporary solution that works.

First copy the resource to the same directory as src folder.

So if your src folder path is C:app/src , then copy all resources to C :app

Run the application again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.