在JavaFX中创建Image时使用文件路径错误,用URL时却没有问题,用的e(fx)licpse

图片说明
该图片存放在相应的src/card/1.png;
求巨巨解惑

官方文档对此的描述是这样:

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);