1

I got this type of file hierarchy in JavaFXApplication5 project.enter image description here

Ive made another package for all the fxml files, so when project gets big it will be easier to find certain files.

Now in JavaFXApplication5 main class I have a line which Im sure causes an exception(java.lang.reflect.InvocationTargetException) when application is trying to run.

AnchorPane root = (AnchorPane) FXMLLoader.load(getClass().getResource("FXMLNew.fxml"));

Im sure its because the "FXMLNew.fxml" root is wrong. But I dont know how to set it when is in another package...?

Or maybe these type of files should be put in normal folder?

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166

1 Answers1

1

To load a fxml which is inside a package, use /package-name/fxml-file-name.fxml

For your case:

AnchorPane root = (AnchorPane)FXMLLoader.load(getClass().getResource("/windows/FXMLNew.fxml"));

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176