0

I'm trying to create application using FXML file for my window, but I can't get this to work, none of answers on StackOverflow worked for me and I'M stuck.

Class where I want to load file

public FXMLWindow() {
        final FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("/test.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
    try {
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}

FXML file

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.FXMLWindow">

and errors

Caused by: java.lang.IllegalStateException: Location is not set.
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2541)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
    at ProgramDlaMamy/com.Window.start(Window.java:21)
  • Does this answer your question? [How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?](https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other) – Alex Jan 31 '22 at 12:14
  • I've changed code to this public FXMLWindow() throws MalformedURLException { FXMLLoader fxmlLoader = new FXMLLoader(); fxmlLoader.setRoot(this); fxmlLoader.setController(this); URL url = getClass().getResource("test.fxml"); try { fxmlLoader.load(url); but still I have the same error – Patryk Łasek Jan 31 '22 at 12:42

0 Answers0