Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes run time error  No class def found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "run time error  No class def found error" Watch "run time error  No class def found error" New topic

run time error No class def found error

bhavani bhavani

Joined: Sep 22, 2004
Posts: 1
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 Source)
at Source)
at$100(Unknown Source)
at$ Source)
at Method)
at 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)
kelly devon
Ranch Hand

Joined: Apr 15, 2004
Posts: 77
giving ur code would help. pls if u can just post it.

Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295

I guess it is due to the class path. This might be a reason.

Try setting the class path with a DOT at the end and try recompiling it.

like set classpath=%classpath%.;

try this and get back. might work.

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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, 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

bhavani, did you get things working?
[ September 22, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
bhavani bhavani,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

I'm thinking that "bhavani bhavani" isn't your real name. Perhaps changing either the first or last part of your display name would suffice.

Thanks Pardner! Hope to see you 'round the Ranch!
I agree. Here's the link:
subject: run time error No class def found error
It's not a secret anymore!