1

I know there have already been some questions about relative paths, but I Keep failing to get JavaFX FXML loader to load a resource from a package other than itself.

The loading class is located in the package gui.controllers and the fxml file BarSheet.fxml is located in the package gui.resources. What should i now put in :

FXMLLoader myLoader = new FXMLLoader(getClass().getResource("src/gui/resources/BarSheet.fxml")); 

Thanks in advance

Domenico
  • 1,331
  • 18
  • 22
Jaap
  • 49
  • 4

2 Answers2

2

SOLVED: The fault was in the fact that my fxml file contained an error so i didnt know when i entered the right path because it would still not work... The path should start with / to indicate the path starting from the root followed by packages/filename. So in my case

FXMLLoader myLoader = new FXMLLoader(getClass().getResource("/gui/resources/BarSheet.fxml"));
Jaap
  • 49
  • 4
1

As a complement when you have a package like com.company.view, and inside you have the .fxml file in order to make this work you have to put the line like this:

FXMLLoader myLoader = new FXMLLoader(getClass().getResource("/com/company/view/file.fxml"));
HebeleHododo
  • 3,620
  • 1
  • 29
  • 38