Jhon Mrag
Jhon Mrag

Reputation: 27

Java reading image but returning null

My program can read images and display them on screen in eclipse but after exporting i get an error saying input == null and it wont display any images.

This calls the load image function

SpriteSheet sheet = new SpriteSheet(ImageLoader.loadImage("/textures/sheet.png"));

This is the loadImage function

public static BufferedImage loadImage(String path){
    try {
        return ImageIO.read(ImageLoader.class.getResource(path));
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    return null;
}

The textures folder is in the jar. It's probably just not finding the file. How can I make this work?

Upvotes: 1

Views: 188

Answers (1)

Lartu
Lartu

Reputation: 188

I had this problem a few days ago while using ImageLoader.class.getResource(path). I solved it by putting my picture folder in the folder where the class file was.

Upvotes: 1

Related Questions