I want to set a window icon for a stage in JavaFX (with a local graphic file).
I tried this code:
stage.getIcons().add(new Image("src/main/resources/images/icon.jpg"));
But I alway get the following error:
Exception in Application start method
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found at
javafx.graphics/javafx.scene.image.Image.validateUrl(Image.java:1099)
I already tried a absolute path, a relative path, copying the image into the root directory, etc. but I always get this error message, exept if I try to use a URL to a graphic on a webserver, e.g.
stage.getIcons().add(new Image("http://example.com/icon.jpg"));
This works.
Edit: I changed the code to
stage.getIcons().add(new Image("file:src/main/resources/images/icon.jpg"));
and it works now!