getResources()返回null [英] getResources() returns null
本文介绍了getResources()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Eclipse IDE。行:
Using Eclipse IDE. The line:
getClass().getResource("/res/bitmaps/image.png");
返回 null
。我在项目根目录下创建了 res
文件夹。
returns null
. I have created the res
folder in the root of my project.
感兴趣的代码是:
bImage = ImageIO.read(getClass().getResource("/res/bitmaps/image.png"));
并抛出异常:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1378)
at com.example.game.resource.Resources._loadImage(Resources.java:31)
at com.example.game.GameComponent.<init>(GameComponent.java:19)
at com.example.game.GameFrame.<init>(GameFrame.java:8)
at com.example.game.GameFrame.main(GameFrame.java:13)
任何帮助?
推荐答案
ImageIO.read(getClass().getResourceAsStream("res/drawable/image.png"));
如果不在课程路径中,可以通过右侧的添加文件夹.. 按钮添加。
Make sure res folder is in class path, verify using project properties > Java build Path > Source tab. If not in class path, can add via Add Folder.. button on the right.
这篇关于getResources()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文