【发布时间】:2017-08-09 08:25:43
【问题描述】:
我想在标签上放一张图片,代码是:
Label userPic = new label();
ImageView userImage = new ImageView(
new Image("test/123/headPortrait.png",50.0,50.0,false,false));
userPic.setGraphic(userImage);
但它不断抛出java.lang.IllegalArgumentException: Invalid URL or resource not found.
我已经尝试过file://headPortrait.png、file://E:/eclipse/ClassSchedule/headPortrait.png(绝对 URL)。这次编译器没有抛出任何异常,但是图像仍然不会显示,并且应用程序运行很慢。
在我尝试将图像添加到标签之前,我的所有代码都运行良好。
【问题讨论】:
-
有效的 url 是
E:/eclipse/ClassSchedule/headPortrait.png或/test/123/headPortrait.png而不是你写的