load fxml javafx in another window Location is not set. code example

Example: javafx fxmlloader location is not set

//CHECK THE FULL ANSWER BUT THIS MIGHT BE A QUICK FIX
 //DON'T USE .. IN THE PATH
 
 // FXML file in the same package as the current class:
 URL fxmlURL = getClass().getResource("MyFile.fxml");
 Parent root = FXMLLoader.load(fxmlURL);

 // FXML file in a subpackage called `fxml`:
 URL fxmlURL2 = getClass().getResource("fxml/MyFile.fxml");
 Parent root2 = FXMLLoader.load(fxmlURL2);

 // Similarly for images:
 URL imageURL = getClass().getResource("myimages/image.png");
 Image image = new Image(imageURL.toExternalForm());

Tags:

Java Example