I'm trying to create a Scene class from a fxml file in the path src/interfaces/panels/, and the file is called StartUp.fxml, but I get this error:
java.lang.NullPointerException: Location is required.
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3230)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at tienda.TIENDA.start(TIENDA.java:30)
public void start(Stage stage) throws Exception {
window=stage;
String path = new File("src/interfaces/panels/StartUp.fxml").getAbsolutePath();
System.out.println(path);//I added this just in case
Parent root = FXMLLoader.load(getClass().getResource("src/interfaces/panels/StartUp.fxml"));//this is the problem
su=new Scene(root);
window.setScene(su);
window.show();
}
EDIT: This was the solution TIENDA is the class, and the path is relative to the class
public void start(Stage stage) throws Exception {
window=stage;
var resource = TIENDA.class.getResource("../src/interfaces/panels/StartUp.fxml");//HERE
System.out.println(resource);
Parent root = FXMLLoader.load(resource);
su=new Scene(root);
window.setScene(su);
window.show();
}