1

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.stack.imgur.com/8T2Nv.png Thats my image of project

Ludvig W
  • 744
  • 8
  • 27

3 Answers3

2

Change the code to:

Icon island =new ImageIcon(ImageIO.read(getClass().getResource("/Island(64x64).png")));   
Akash Rajbanshi
  • 1,553
  • 11
  • 23
1

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.

kiheru
  • 6,588
  • 25
  • 31
0

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

  • Well, i wanted to not need to do that, i mean simply include images in the JAR to be able to upload it so people can download just one single file – Ludvig W May 21 '15 at 13:49