I have built my application using scenebuilder for javafx. I have a form where a person has to upload an image. I used this code
public void photoChooser(Act
The constructor of Image
expects an URL and not a file path. Therefore if there is a ":" in the string, everything up to that point is interpreted as the protocol (normally something like http
, file
or ftp
).
You have to change the line
String img = file.toString();
to
String img = file.toURI().toURL().toExternalForm();
This gets the URL from the file before converting to string. I converted to URI first since File.toURL
is deprecated and that's the suggested "workaround".