该图片存放在相应的src/card/1.png;
求巨巨解惑
在JavaFX中创建Image时使用文件路径错误,用URL时却没有问题,用的e(fx)licpse
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 战在春秋 2017-04-03 07:05关注
官方文档对此的描述是这样:
If the passed string is not a valid URL, but a path instead, the Image is searched on the classpath in that case。
传入path是可以的,但要确保能找到。
两个例子:
// The image is located in default package of the classpath Image image1 = new Image("/flower.png", true);
// The image is located in my.res package of the classpath Image image2 = new Image("my/res/flower.png", 100, 150, false, false);
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报