Sign in to follow this  
Gixugif

[java] Java: getResourceAsStream() returning null

Recommended Posts

[code]BufferedImage = ImageIO.read(getClass().getResourceAsStream("/Images/player.gif"));
[/code]

The file getResourceAsStream is looking at definitely exists (it's a variable in the actual code, but I figure simpler to write it out here), but for whatever reason, "is" is null on the next line. I'm guessing there's something I don't understand about how this works, but anything I've read so far on the matter hasn't been at all helpful, so I would be thankful for anyone who can explain to me what's going on.

I'm sure it's not an issue of where the file is located. My classes are in /src in the DreamGame folder, and as you can see, Images is in the Images folder.

Share this post


Link to post
Share on other sites
Oops, sorry, took a while for me to get back to this. Edited the line in the op a little bit, but shouldn't have made a functional difference.

So the problem was it was looking for "/Images" in the bin directory when the contents of "/Images" were in bin, but not "/Images" itself. Changing the code to read "/player.gif" instead of "/Images/player.gif" fixed this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this