1

My program runs fine in Netbeans, but I get the following error when I run my applet in a browser:

java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)

I opened the jar to verify that the png files are correctly placed there. I'm not certain why the following doesn't work (in a try block, of course):

BufferedImage beam = ImageIO.read(this.getClass().getResource("images/beam.png"));

I've tried other things like the following, but suspect the problem might be something else.

URL url = this.getClass().getResource("images/beam.png");
BufferedImage beam = ImageIO.read(url.openStream());

Your advice is appreciated.

4

2 回答 2

1

问题出在您的路径字符串中。改用这个:

BufferedImage beam = ImageIO.read(this.getClass().getResource("/images/beam.png"));

(注意/路径前)

于 2012-10-11T14:26:21.003 回答
0

作为记录,如果有人由于某种原因遇到这种类型的错误,eclipse 会自动更改构建路径并阻止图像路径被打包。

要更改此设置,只需right click on the project name-> Properties-> Java Build Path->Source Tab并检查是否不排除包含图像的文件夹,如果它只是删除该规则。

于 2019-04-19T21:31:44.813 回答