我遇到了一个奇怪的问题。这是我的代码片段:
...
public xProgressBar(xTheme theme) {
try {
this.update = ImageIO.read(xTheme.class.getResource("/images/" + xThemeSettings.PROGRESSBAR_IMAGES[0]));
}
...
当我运行程序时,出现以下错误:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
这是文件结构:
如您所见,res
文件夹与 src
文件夹位于根目录。我读过很多类似的问题,但没有任何帮助。
最佳答案
为了让 getResource
找到文件,相应的文件夹(在本例中为 res
)需要位于 classpath
中。如果它不在类路径中,则 getResource
返回的 InputStream
将始终为 null
。
Here's如何将文件夹添加到类路径
中。
关于java - ImageIO.read getResource 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44216996/