I'm fairly new to graphical libraries, in this case, JavaFX, and I wanted to add an icon to my project. So I googled and found two different methods: The first one was pretty straightforward:
stage.getIcons().add(new Image("300px-Wikibooks-logo.png"));
That just put out an error message, that the URL isn't valid.
The second method is very similar:
stage.getIcons().add(new Image(getClass().getResourceAsStream("300px-Wikibooks-logo.png")));
This one doesn't fail. It compiles and runs just fine, but the icon isn't showing up. I even tried every single location in my program and I used every "Copy Path" option. I also read that there should be a / in front of the pathname, but I didn't work with it either.
For better visualization, here is my file tree:
Aufgabenblatt5
---.idea
---src
-----main
-------java
---------de.ab5.abgabe5
-----------(here are all my classes)
-------resources
---------de.ab5.abgabe5
-----------(here was the image file while it worked)
----target
Maybe someone can help.