Ludvig W
Ludvig W

Reputation: 824

Eclipse run my program well however JAR-file does not

I have four classes in my game; Player.java, Game.java, Island.java and Map.java. And basically its plenty of code to link here however my issue is that my program works fine in eclipse but when i export as jar and run it nothing is opened so i open it with CMD and it gives errors.

Input in CMD:

java -jar GameAlliansen.jar

Output from CMD:

Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.

This is how i import my images

 island = new ImageIcon(Game.class.getResource("/Island(64x64).png"));

https://i.sstatic.net/8T2Nv.png Thats my image of project

Upvotes: 1

Views: 124

Answers (3)

kiheru
kiheru

Reputation: 6618

The paths inside jars are case sensitive, whereas not all filesystems are (such as the one used by Windows is just case preserving, not case sensitive). You're trying to load "Island(64x64).png", but the image shows the actual filename is "island(64x64).png". Change these to match.

Upvotes: 1

Normal design
Normal design

Reputation: 148

When you export it, create a folder in which you will put your jar file and ALSO the image Island(64x64).png

Upvotes: 0

Akash Rajbanshi
Akash Rajbanshi

Reputation: 1593

Change the code to:

Icon island =new ImageIcon(ImageIO.read(getClass().getResource("/Island(64x64).png")));   

Upvotes: 2

Related Questions