This error is telling you that you that the
Java Virtual Machine cannot find the class you are trying to run. The �wrong name� portion of the message indicates you are not properly identifying your class when trying to run it because it is part of a package. This is something that many beginners have a some trouble with.
Take a look at the following class:
Notice that class is part of the package �com.foo�. If I try to run this class with the com\foo directory as my classpath entry, I will get a similar error as you are getting:
On my system, as most systems, my system�s classpath has an entry of . (just a dot) which means current directory. So if I do the following, I get the same error since the working directory of �D:\Dev\Misc\com\foo\� becomes part of my classpath:
The reason is that the full and proper name of the class is not �MyClass� but rather �com.foo.MyClass�. Therefore I need to identify it as such, and have the directory that contains the package,
not the class, in my classpath:
Or if I rely on my system�s classpath entry to leverage the current working directory:
Lastly, as a side note, instead of identifying the (full name of the) class with dot notation, you can use also use forward slashes (not the backslashes that Windows uses) like this:
However, the dot notation is more standard and generally preferred (and just makes more sense since the
true name of the class is �com.foo.MyClass� and not �com/foo/MyClass�.
For some more information and guidance, take a look at the
How To Set The Classpath article in the
Java Beginners Faq section of JavaRanch's
Frequently Asked Questions page. Also look at
Your First Cup of Java on the Sun Tutorial.
For more information on packages look at the
Interfaces and Packages lesson on the Sun Tutorial Site.
[ January 24, 2004: Message edited by: Mark Vender ]