0

I wanted to migrate my local prototype to a maven build and start getting productive. But unfortunately when calling

loader.setLocation(getClass().getResource("views/TaskWindow.fxml"));

On runtime it seems that maven doenst find the ressource xmls. I tryed "TaksWindow.xml", "../views/TaksWindow.xml" "views/TaskWindow.xml" and "/views/TaksWindow.xml" but somehow it always gives me "no location set" error.

My project structure looks like this:

enter image description here

Any ideas why?

  • First maven has nothing to do with finding resources..Your code does not correctly find the resources. The question is where have you located the resources you are trying to load? – khmarbaise Apr 30 '18 at 14:38
  • edited the structure in. – Simon Bauer Apr 30 '18 at 14:38
  • Ah ok..than you have to use `getClass().getResource("/views/TaskWindow.fxml")´. The leading slash is important otherwise the loading is realtive to the class in which you are using this.... – khmarbaise Apr 30 '18 at 14:41
  • beautiful!! I thought i tryed that alread... must have slipped a class and then crashed the whole application... – Simon Bauer Apr 30 '18 at 14:44

1 Answers1

1

The path you specified is a relative path. Which means the classloader will look for a views folder at the location of the class (i. e. its package). You propably want to use an absolute path.

Try the following code, notice the leading /.

getClass().getResource("/views/TaskWindow.fxml")

For more information, see this answer.

SilverNak
  • 3,283
  • 4
  • 28
  • 44