My FXMLLoader
doesn't seem to find my fxml-file which is located in the resources folder.
I'm using gradle to run my project. Since the structure is already give, I've created a new Scene and am now trying to load it.
Main:
public class App extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("LoginWindow.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException ignore) {
// ignore for the time being
}
}
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.2"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.pm2.SportHub.controller.LoginController">
<children>
<Label layoutX="14.0" layoutY="14.0" text="Hallo Welt" />
</children>
</AnchorPane>
The error message is as follows:
java.lang.reflect.InvocationTargetException
Caused by: java.lang.RuntimeException: Exception in Application start method
Caused by: java.lang.IllegalStateException: Location is not set.
In theory this should work just fine but it doesn't. Can someone explain me what I'm doing wrong?
Note: LoginController.java
is in a package called controller and the class is currently empty.