I have a simple java project and I have a class called Constants where I store all my required paths in static variables, like this for example:
public static final String PLAYFIELD_SMALL_IMAGE_PATH = Constants.class.getClassLoader().getResource("Player_Small.png").getPath();
Works fine as long as I stay in my Eclipse ;)
but when I export my program to a JAR file and start it I get an exception:
java.lang.ExceptionInInitializerError
it appears when I call the following for the first time:
Constants.PLAYFIELD_SMALL_IMAGE_PATH
If I start a second time I get this error:
java.lang.NoClassDefFound: Could not initalize class Constants
What am I actually doing wrong?
EDIT 1:
I found this one here : "NoClassDefFoundError: Could not initialize class" error
Seems to be exactly the same problem. So should I not use static variables?
EDIT 2:
If I use a static initializer block an ExceptionInInitializerError is thrown instantly. without a static initializer block I was able to get to the first menu of my program.
EDIT 3:
Maybe another hint! When I extract my jar all graphics are directly in the root-folder so i tried to use a relative path like this:
public static final String PLAYFIELD_SMALL_IMAGE_PATH = "Player_Small.png";
But if i do so my graphic isnt loaded.