简体   繁体   中英

Java Swing: Images not Displaying when run from jar file

Swing application and it's Images are running fine in eclipse. but when i run from jar file, images not displaying. I tryed to load images in different way, but some time jar file not executing.

My image folder is inside of source folder.

I load my images with:

1.Running fine in eclipse, but not in jar

ImageIcon right = new ImageIcon("./chack img/Green Tick 1.PNG");

2.Running fine in eclipse, but jar file not executing.

ImageIcon wrong = new javax.swing.ImageIcon(getClass().getResource("/chack img/Red Cross1.PNG"));

I tryed some other code also, still my issue not solved.

Put your images in the src folder, along with your classes. Optional, but make a package that stores your images. Compiling a jar file will not keep any directories that are not a source directory.

Also, remove all spaces from your folders and file names. This prevents confusion, and is likely part of your problem. No spacing is a good practice to follow in programming, and in most situations of naming folders and files.

Also, kiheru is correct, you should not have capital letters in the file extensions, for the same reason you should not have spaces; It can cause confusion and it is a bad practice in most cases.

EDIT: Simmilar Question

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM