• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

run time error No class def found error

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
giving ur code would help. pls if u can just post it.
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic