Author | Message |
---|---|
knagrec2
Posts: 51
|
Posted 11:11 Nov 13, 2018 |
I am simply trying to access my image file (which is in the project folder) by using "cards//1.png". It works fine on the File class: the file.exists() method returns true. However, when I plug it into the Image object constructor, I get an error Invalid URL or resource not found. Is there a way to use the file in the constructor instead of the filePath? |
kknaur
Posts: 540
|
Posted 11:18 Nov 13, 2018 |
I explained this during the lecture. Files for File I/O and the File class are relative to the project folder. Files for resources for JavaFX such as images, sounds, video clips, etc are relative to the src folder. |
knagrec2
Posts: 51
|
Posted 11:28 Nov 13, 2018 |
It should still work if I give an absolute file path too right? I tried using an absolute path just to test it and it still wouldn't load. |
knagrec2
Posts: 51
|
Posted 11:46 Nov 13, 2018 |
I got it to work by adding "file:" before the path. |
kknaur
Posts: 540
|
Posted 12:02 Nov 13, 2018 |
At that point I would have to see what your setup is. "file: " might work, but maybe only for your computer? I have never used this so I can't say for sure if it will work on all systems. |