2

I have a JavaFX program that uses Maven, with a standard maven file tree:

enter image description here

How do I reference logo.png from within layout.fxml, assuming that layout is being inflated by a call to

Parent root = FXMLLoader.load(getClass().getResource("/fxml/layout.fxml"));

in MainApp.

I've trying to do so using

<image>
<Image url="@/graphics/logo.png" />
</image>

and have tried many variations on that file path (with and without the @), but keep throwing a

java.lang.reflect.InvocationTargetException 
... 
Caused by: java.lang.IllegalArgumentException: URL must not be empty

on the line where the URL is created

drew moore
  • 31,565
  • 17
  • 75
  • 112

1 Answers1

2

You are trying to locate the image resource with name "backButton.png" whereas it should be "logo.png".

If the problem persists, try as

<Image url="@../graphics/logo.png" />

since from official FXML tutorial:

The location resolution operator (represented by an "@" prefix to the attribute value) is used to specify that an attribute value should be treated as a location relative to the current file rather than a simple string.

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • The filename was just a typo here, it's correct in my program. Your suggestion did not help, however. I'm afraid this is caused by the fact that, if `@` is relative to the fxml file, `graphics` is not accessible as a child folder. It's a sibling of the fxml folder under the parent `resources` folder. – drew moore Feb 07 '14 at 06:22
  • @drewmore, ".." means the parent folder of the current location, i.e. the parent folder of FXML folder. So the path "../graphics" is correct. To confirm the package structure, unzip the produced jar file and check the folders and the location of the mentioned image in them. – Uluk Biy Feb 07 '14 at 06:30
  • Hey why -1. Can the one who did it explain the reason of his/her act? – Uluk Biy Feb 07 '14 at 06:32