i got below error while running java program IS this related to class path please tell me why it is coming any help will be appreciated
Exception in thread "main" java.lang.NoClassDefFoundError: MainTranslator (wrong name: HW1_271/MainTranslator) at java.lang.ClassLoader.defineClass0(Native Method) 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$100(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) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Concerning setting the CLASSPATH, on Windows you separate locations with a semicolon, on Linux/UNIX/Mac OS, you use a colon.
So, in the above example, on Windows, the period should be moved to be after the semicolon - %CLASSPATH%;.
But I don't think this really gets at the problem the initial poster is having. In that problem, it looks like you're trying to run the main class of a Java program from the wrong directory. Consider this example:
Working in the /temp folder, if I compile the following class with the command javac Foo.java, it places a file named Foo.class in the /temp directory. Working from within this same directory, if I try to run this program, the following error message is spit out:
Exception in thread "main" java.lang.NoClassDefFoundError: Foo (wrong name: fubar/Foo)
If I do the proper thing, and place the Foo.class in the fubar directory, which matches the name of the package that this class is declared to belong to, then things will work out better. So, still working within the /temp directory, I place the Foo.class file in /temp/fubar. Now, from the /temp directory, I can run it with the command java fubar.Foo.
Note that if I were to change my working directory to /temp/fubar, and try to run Foo with the command java Foo, I'd get the same error message as above.
Also note: You'll still need to have a properly specified CLASSPATH. On a Windows machine (and maybe on Linux and Mac OS, as well), that could simply mean not setting your CLASSPATH. If the CLASSPATH is not specified, then the JRE includes the current working directory automatically. If you specify one, then you'll likely want to make sure it includes the current working directory, as specified by a period. The steps to take to set the CLASSPATH on different systems are described at http://faq.javaranch.com/view?HowToSetTheClasspath
bhavani, did you get things working? [ September 22, 2004: Message edited by: Dirk Schreckmann ]