0

Help please, I am new to programming and have built a little tennis app. The game works when i run it through eclipse, however, when I export it as a jar the images don't show. I have a class just for the images with a static method.

public static Image getImage(String fileName){
    Image img = null;
    File file = new File(fileName);
    try {
        img = ImageIO.read(file);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return img;     
}

My folder structure is like this.

folder structure

The get image is called from various classes. Below is an example of how its called.

public Ball(double x, double y){
    super(x,y,BALL_DIAMETER, BALL_DIAMETER);
    this.x = x;
    this.y = y;
    //Get the image.
    imgBall = Images.getImage("src/resources/ball.png");
}//End of constructor

Thanks for any help much appreciated

I have tried this in the image class but it didn't work.

public static Image getImage(String fileName){
    Image img = null;
    URL url = Images.class.getResource(fileName);
    try {
        img = ImageIO.read(url);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return img;     
}

0 Answers0