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)