This content has been marked as final. Show 2 replies
The file chooser chooses a file from anywhere on the OS file system.
Class resources are generally not files for JavaFX applications as javafx applications are usually packaged as jars.
When you use getClass().getResourceAsStream(someLocation), you are specifying to use the protocol used by the class' classloader, which in a jar packaged JavaFX application will be a jar protocol, but you are not supplying a valid jar protocol location to your call, so the system cannot find the resource you are asking it to find. You cannot use a FileChooser to choose files out of a jar.
Instead, you should use something like the following which will use the file protocol to access the file chosen from the OS filesystem by the file chooser:
Here is a sample png image viewer application where you can see this in action: https://gist.github.com/jewelsea/5165446
Perfect. Thank you very much. Have a nice weekend ;-)