BufferedImage = ImageIO.read(getClass().getResourceAsStream("/Images/player.gif"));
First of all, yes I did add the image folder to my classpath.
For this I receive the error java.lang.IllegalArgumentException: input == null!
I don't understand why the above code doesn't work. From everything I read, I don't see why it wouldn't. I've been told I should be using FileInputStream
instead of GetResourceAsStream
, but, as I just said, I don't see why. I've read documentation on the methods and various guides and this seems like it would work.
Edit: Okay, trying to clear some things up with regards to what I have in the classpath.
This is a project created in Eclipse. Everything is in the project folder DreamGame
, including the "Images" folder. DreamGame
is, of course, in the classpath. I know this works because I'm reading a text file in /Images
with info on the gif earlier on in the code.
So I have: /DreamGame/Images/player.gif
Edit 2: The line that's currently in the original post is all that's being passed; no /DreamGame/Images/player.gif
, just /Images/player.gif
. This is from a method in the class ImagesLoader
which is called when an object from PlayerSprite
is created. The main class is DreamGame
. I'm running the code right from Eclipse using the Run
option with no special parameters
Trying to figure out how to find which class loader is loading the class. Sorry, compared to most people I'm pretty new at this.
Okay, this is what getClassLoader()
gets me: sun.misc.Launcher$AppClassLoader@4ba778
getClass().getResource(getClass().getName() + ".class")
returns /home/gixugif/Documents/projects/DreamGame/bin/ImagesLoader.class
The image file is being put in bin
as well. To double check I deleted the file from bin
, cleaned the project, and ran it. Still having the same problem, and the image file is back in bin