有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JAVAlang.IllegalArgumentException:找不到无效的URL或资源。JavaFX图像

我正在使用Dropbox API V2将图像从Dropbox下载到Java程序。我将它们保存在"/src/main/Resources/Downloads/"中,然后希望在下载后程序运行的同时获取image.jpg

1)程序第一次下载图像并运行此操作时,我收到“无效URL或未找到资源”错误:

Button button1 = new Button();
Image thumbnail = new Image("/Downloads/image.jpg");
button1.setGraphic(new ImageView(thumbnail));

2)第二次,当我关闭程序并且文件已经保存在资源中时,它可以工作

我错过了什么


共 (1) 个答案

  1. # 1 楼答案

    找到了解决方案:

    String path = "/src/main/Resources/";
    
    File file = new File(path + i.getLocalPathThumbnail());
    String localUrl = file.toURI().toURL().toString();
    Image thumbnail = new Image(localUrl, false);