This has been driving me nuts for the past hour. I have two computers, one I work on primarily running linux mint 11 and the following version of the JDK:
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.5) (6b20-1.9.5-0ubuntu1~9.10.1)
OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)
Now on my windows computer I’m trying to use the same code I have compiled and ran on the linux one. The windows one is running XP with the following java:
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
I know the versions are different but should that really make a difference with something as simple as a nested class? I really hope I just made a mistake in the following code:
public class test {
public static class nClass
{
public void testFunc()
{
System.out.println("Test worked.");
}
}
public static void main(String args[]) {
test.nClass t = new test.nClass();
t.testFunc();
}
}
This code compiles and runs fine on the linux computer. When I bring it over to the windows one it will compile fine but produces:
NoClassDefFoundError test$nClass at test.main(test.java:10)
I’m completely stumped and entirely frustrated.
My guess is that you only copied the
test.classfile – you need to copytest$nClass.classas well… or recompile on Windows.(Note that these names don’t follow Java naming conventions. It’s not relevant to the question, but it’s a good idea to follow conventions even for sample code.)