I made a game in Java. It works completly fine in Eclipse.
I exported it as a Runnable JAR. When double-clicking on it's icon, it doesn't open. So I tried running the JAR from the command line.
I get a NullPointerException
error, in a line of code that's trying to retrieve an image resource (as I said, it works fine inside Eclipse). This is the line of code where the error happens:
ball = new ImageIcon(this.getClass().getResource("sprites/ball.PNG"));
I have no idea what's wrong. Here is the structure of my project:
Any ideas? I'm starting to get desperate.
Thanks a lot for your help.
EDIT: I tried adding a /
to the beginning of sprites/ball.PNG
. Didn't help. Also tried to change PNG
to png
. Didn't work either.
Checked inside the JAR, the image is inside. I'm on Windows.
Here is the stacktrace:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init><Unknown Source>
at instPanel.<init><instPanel.java:17>
at Main.<init><Main.java:23>
at Main.main<Main.java:38>
EDIT: Could the fact that I'm using (default package) be a problem?