This is my first post - I found similar problems, but nothing about this problem. It sounds very simple, but I don’t quite understand why this is happening. My program works fine in Eclipse, but not from the command line. I have several classes in a simpletree package.
Here is BinaryTree.java :
package simpletree;
import java.io.*;
public class BinaryTree implements Serializable {
private static final long serialVersionUID = -3124224583476129954L;
BinaryTree leftNode;
BinaryTree rightNode;
}
class Tree implements Serializable {
private static final long serialVersionUID = 6591795896216994405L;
private BinaryTree root;
}
And Program1Test.java :
package simpletree;
public class Program1Test {
public static void main(String[] args) {
Tree tree = new Tree();
}
}
Here's the problem : doing it from within simpletree compiles fine:
javac BinaryTree.java Program1Test.java
When I do this:
java Program1Test
I get this:
Exception in thread "main" java.lang.NoClassDefFoundError: Program1Test (wrong n
ame: simpletree/Program1Test)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Program1Test. Program will exit.
Any ideas? I have the correct path to the class, and I tried to work with the package (simpletree.Program1Test) and without it.
source
share