Problem with packages on Windows XP
807597Mar 26 2005 — edited Mar 26 2005Hello everybody,
I am trying to learn how to use packages in Java. I've written a "Hello World" type program called Test.java with a package statement that says "package MyPackage;". The class file is in a directory named MyPackage.
If I try to run the program from the MyPackage directory, I get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong name: MyPackage/Test)
If I go back a level in the directory structure and type: java MyPackage/Test, it works.
If I try typing: java -classpath MyPackage Test, I get the error again.
I have also tried adding the class to a .jar file. If I omit the package statement, it works perfectly. With the package statement, I am unable to get it to run.
I've checked the tutorial and my Java reference book but haven't been able to solve the problem.
Can anybody tell me what I'm doing wrong?