I think you mean you get a NoClassDefFoundError
like this:
NoClassDefFoundError: Could not initialize class SomeHelper
As JavaSE-7 states:
NoClassDefFoundError thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
Sometimes NoClassDefFoundError
occurs if the static bits of your class i.e. any initialization that takes place during the defining of the class, fails.
So first change
private int static x;
to,
private static int x;
Declare setX()
as static
, or create instance of SomeHelper
to invoke setX()
.
To invoke any method with the class name, the method should be static
.
Try this:
public static void setX(int value){
x = value;
}
SomeHelper.setX(someInteger);
Or this:
SomeHelper someHelper = new SomeHelper (); // default constructor
someHelper .setX(someInteger);
Note that, You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors.