Skip to Main Content

Problem loading images from jar file, which work fine on BlueJ IDE.

User_FYNVANov 26 2022

I created an executable jar file containing a java swing project and a few images. The images work fine on BlueJ IDE, but after compiling the project and images into a jar file, the images do not load on running from the jar file. I searched Google to find a few solutions but none of them seem to work for me. BlueJ(version:5.1.0) is the only IDE that I use, I am a class-9 ICSE student from India and don't have much experience, this is my first Java swing project, which I copied from a source on the internet. Please help.

private final int NUM_IMAGES = 13;
img = new Image[NUM_IMAGES];
for (int i = 0; i < NUM_IMAGES; i++) {
var path = "src/resources/" + i + ".png";
img[i] = (new ImageIcon(path)).getImage();

This is the code snippet that I used.
The original code can be found at:
Java Minesweeper - creating Minesweeper game clone in Java (0 Bytes)

Post Details
Added on Nov 26 2022
1 comment