0

I'm trying to load a .fxml file from some package and can't manage to do it.

Here is my file tree :

enter image description here

And here's the viewService which tries to return an FXML loader set to my fxml file :

private static FXMLLoader getLoader(String id) {
    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(App.class.getResource("/" + id + ".fxml"));
        loader.load();
        return loader;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

I've read everywhere that i needed to kind of reproduce the tree of my package in my resources folder but i can't manage to do it correctly : Everytime i try, i'm getting something like this and it doesn't work :

enter image description here

I am getting mad on this, please help me !

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77

1 Answers1

0

I had such a problems with the path I was working with eclipse , as I found after solving my problem the fxml file path is written relative to the src folder which becomes the bin when you compile it

I don't know what is the String id in your code but it should be

 FXMLLoader loader = new FXMLLoader(getClass().getResource("/main/ressources/file_name.fxml"));

if you want to see my working project this image shows the project structure and the loader code Image

Ibraheem Alyan
  • 426
  • 1
  • 5
  • 14