I have a problem regarding the ImageIO.read() function:
URL imageURL = this.getClass().getResource(sheetPath);
spriteSheet = ImageIO.read(imageURL);
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?
Regards
Edit:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.