Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

run time error No class def found error

 
bhavani bhavani
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
giving ur code would help. pls if u can just post it.
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic