Loading an image in ImageView through code

被刻印的时光 ゝ 提交于 2019-11-29 15:34:55

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".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!