I am currently trying to load a spritesheet for a small game I am working on. The issue is that piece of code here:
private void load(){
try {
BufferedImage image = ImageIO.read(Sprite.class.getResource(path));
int w = image.getWidth();
int h = image.getHeight();
image.getRGB(0, 0, w, h, pixels, 0, w);
} catch (IOException e) {
e.printStackTrace();
}
}
ImageIO.read() always returns null. It also doesn’t throw any exceptions. Obviously, I get a error on the next line as I call image.getWidth() as image is null.
What really bothers me is that the same piece of code worked completely fine 10 minutes ago. I haven’t changed anything but a value that doesn’t affect the reading process at all; even changing it back wouldn’t do anything.
Does anyone know what to do here?
I think that your problem is here:
You can write this line out and check that is your path right or not.
This problem occurs when your file path is not true. Check your file path by using this line of code:
then you can find the problem.