This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

run time error No class def found error

bhavani bhavani
Greenhorn

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 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)
kelly devon
Ranch Hand

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


kel
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi,

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.

Cheers,
Swamy
Dirk Schreckmann
Sheriff

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 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 ]

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

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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: run time error No class def found error
 
Similar Threads
Ant build - With weblogic 10
Exception when invoking standalone client
Problem running an applet
abstract class
Why I can't run Web Start when my class using hibernate?