Jump to content
  • Advertisement
Sign in to follow this  
Gixugif

[java] Java: getResourceAsStream() returning null

This topic is 2596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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


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
Advertisement
If you want to directly load a file, you can use a FileInputStream. Using getResourceAsStream is different from simply loading a file, as 6510 suggests.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!