Cannot start multiprocessor program from command line using packages

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 {
       // Automatically generated UID
       private static final long serialVersionUID = -3124224583476129954L;

       BinaryTree leftNode; // left node
       BinaryTree rightNode; // right node  

       // some code
    }

    class Tree implements Serializable {
    private static final long serialVersionUID = 6591795896216994405L;
    private BinaryTree root;

    // some code    
    }

And Program1Test.java :

    package simpletree;

    public class Program1Test {
    public static void main(String[] args) {
        Tree tree = new Tree();
                // some code
    }
    }

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.

+3
source share
2

java simpletree.Program1Test

dir simpletree

-cp

+4
  • .class "simpletree"
  • :

    java simpletree.Program1Test

+2

All Articles