piagetD 2017-04-03 06:39 采纳率: 25%
浏览 3368
已采纳

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

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

  • 写回答

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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?