ImageIO的Java未知源 [英] Java unknown source with ImageIO
本文介绍了ImageIO的Java未知源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序在Netbeans中运行良好,但是在浏览器中运行小程序时出现以下错误:
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)
我打开罐子,以验证png文件是否正确放置在其中.我不确定以下原因为何不起作用(当然,在try块中):
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());
您的建议受到赞赏.
推荐答案
问题出在您的字符串路径中.改用它:
The problem is in your path String. Use this instead:
BufferedImage beam = ImageIO.read(this.getClass().getResource("/images/beam.png"));
(请注意路径前的/
)
这篇关于ImageIO的Java未知源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文