Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with packages on Windows XP

807597Mar 26 2005 — edited Mar 26 2005
Hello 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 23 2005
Added on Mar 26 2005
3 comments
173 views