【发布时间】:2018-06-26 06:10:49
【问题描述】:
我刚刚在 Java 中遇到了一个错误(使用 Eclipse)。我想将资源文件夹中的图像加载到应用程序中。使用以下几行:
URL url = this.getClass().getClassLoader().getResource("/resources/images/icon.png");
BufferedImage i = ImageIO.read(url);
但这会导致java.lang.IllegalArgumentException: input == null! 异常。
我的文件夹结构是:
如何访问此图像?非常感谢!
【问题讨论】:
-
我认为您不必在请求中包含“资源”(因此:getResource("/images/icon.png");)
-
另外,如果我的建议不起作用,我建议你下一个断点并使用评估器尝试一下
-
不起作用,同样的问题。
-
此时你真的需要 getClassLoader() 吗? this.getClass().getResource() 工作正常。