Issue
I know this has been asked many times and I have searched far and wide for a solution to this probably simple problem. I'm trying to follow the simple javaFX component tutorials on Oracle's website. I can define an image this way:
Image img = new Image("images/portal.png", 50, 50, true, true);
This works when the image is in a folder inside the "src" folder, but I'm trying to get it to find the image when I have the image folder outside of the "src" folder, like this:
project_root/
|---src/
|---Main.java
|---images/
|---portal.png
How can I make this work? All I get is errors saying "Invalid URL or resource not found". I've tried to use the absolute path, tried putting ".." infront of it, tried "HS-Graph/images/portal.png" and everything inbetween :( Thank you!
Solution
I'm going to answer my own question as I actually found a solution to this! My solution is to use the "file:" prefix when specifying a path. So:
Image img = new Image("file:images/portal.png");
Works perfectly when the image file is outside of my src folder!
Answered By - Zorobay
Answer Checked By - Clifford M. (JavaFixing Volunteer)