java.lang.IllegalArgumentException:无效的URL或资源未找到.JavaFX图片 [英] java.lang.IllegalArgumentException: Invalid URL or resource not found. JavaFX image
本文介绍了java.lang.IllegalArgumentException:无效的URL或资源未找到.JavaFX图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Dropbox API V2将图像从我的Dropbox下载到我的Java程序.我将它们保存在"/src/main/Resources/Downloads/"
中,然后希望在下载后程序运行的同时获取 image.jpg
.
I'm using Dropbox API V2 to download images from my Dropbox to my Java Program. I save them in "/src/main/Resources/Downloads/"
and then want to get the image.jpg
at the same time the program is running after downloaded.
1)程序第一次下载图像并运行该图像时,出现无效的URL或找不到资源"错误:
1) The first time the program downloads the image and run this I get "Invalid URL or resource not found" error:
Button button1 = new Button();
Image thumbnail = new Image("/Downloads/image.jpg");
button1.setGraphic(new ImageView(thumbnail));
2)第二次关闭程序并且文件已经保存在资源"中了.
2) Second time when I have closed the program and the file is already saved in Resources it works.
我想念什么?
推荐答案
找到了解决方案:
String path = "/src/main/Resources/";
File file = new File(path + i.getLocalPathThumbnail());
String localUrl = file.toURI().toURL().toString();
Image thumbnail = new Image(localUrl, false);
这篇关于java.lang.IllegalArgumentException:无效的URL或资源未找到.JavaFX图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文