Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

java - getResources() returns null

Using Eclipse IDE. The line:

getClass().getResource("/res/bitmaps/image.png");

returns null. I have created the res folder in the root of my project.

The code of interest is:

bImage = ImageIO.read(getClass().getResource("/res/bitmaps/image.png"));

and it throws the exception:

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)

Any help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...