The World’s Largest Online Community for Developers

'; java - returns null - LavOzs.Com

I have a problem regarding the function:

URL imageURL = this.getClass().getResource(sheetPath);
spriteSheet =; 

The ImageIO function returns null even though the URL is correct (it leads to a .png file). I've tried to put the getResource() as a parameter for the read function, but that didn't work either. Has anyone encountered a similar problem and maybe found a solution?



sheetPath is "/images/pizzaGirl.png"

imageURL is "file:/Users/Kevin/Dropbox/workspace/PizzaGirl/bin/images/pizzaGirl.png"

images is in the "res" folder which I added to the classpath via the eclipse's run configurations

Okay I tried to replace my path with a different image and it worked. I went back into photoshop, exported my image again and voilà, it works.

Check if the path is really correct. To do this write:

System.out.println(new File(yourPathHere).exists());

then if it returns false please post the path. I will check if it is correct.

Avoiding != null statements
Is null check needed before calling instanceof?
Creating a BufferedImage from .tiff file
getClass().getResource() always returning null
Can't start Eclipse - Java was started but returned exit code=13
Java resources, returns nullpointer
getResource(String name) returns null? takes forever loading an image
Illegal Argument exception thrown by