This discussion is archived
7 Replies Latest reply: Nov 4, 2007 11:44 PM by 791266 RSS

NoCLassFound Exception (wrong name)

807587 Newbie
Currently Being Moderated
I get a NoClassDefFoundException when I try to execute one of my java classes.It compiles fine but it throws thois exception while execution...
the exception is as follows...can anyone tell me what cud be the reasons for this.My classpath is set correctly I am sure abt it.
$ java examples/TestRcf
Exception in thread "main" java.lang.NoClassDefFoundError: examples/TestRcf (wrong name: TestRcf)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
  • 1. Re: NoCLassFound Exception (wrong name)
    807587 Newbie
    Currently Being Moderated
    You need to put the class name. Perhaps you ment examples.TestRcf
  • 2. Re: NoCLassFound Exception (wrong name)
    807587 Newbie
    Currently Being Moderated
    TestRcf is the class name.its in a package in that directory called examples.
  • 3. Re: NoCLassFound Exception (wrong name)
    807587 Newbie
    Currently Being Moderated
    You didn't understand Mr. Lawrey's correct answer.
    $ java examples.TestRcf
  • 4. Re: NoCLassFound Exception (wrong name)
    807587 Newbie
    Currently Being Moderated
    I get the same error eve with this...

    $ java examples.TestRcf
    Exception in thread "main" java.lang.NoClassDefFoundError: examples/TestRcf (wrong name: TestRcf)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
  • 5. Re: NoCLassFound Exception (wrong name)
    800560 Newbie
    Currently Being Moderated
    Exception in thread "main"
    java.lang.NoClassDefFoundError: examples/TestRcf
    (wrong name: TestRcf)
    at java.lang.ClassLoader.defineClass1(Native
    1(Native Method)
    This error means that the .class file that the java.exe launcher found had a class named TestRCF in it, while the class you specified is examples.TestRcf. You can use / or . as a package name/class name separator.

    Sounds like you either did not start the source code with the line "package examples;" or you have more than one TestRcf.class file.
  • 6. Re: NoCLassFound Exception (wrong name)
    807592 Newbie
    Currently Being Moderated
    I've been fighting this problem for two weeks now. Everything works great until I convert to applet and try to run in a browser. I've been writing computer code since 1974 and nothing has frustrated me more than Java!

    load: class propmgmt903.class not found.
    java.lang.ClassNotFoundException: propmgmt903.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more

    or even with the class file in the same directory as the html file

    java.lang.NoClassDefFoundError: propmgmt903 (wrong name: propmgmt903/propmgmt903)
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(Unknown Source)
         at java.security.SecureClassLoader.defineClass(Unknown Source)
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)


    Any ideas......
  • 7. Re: NoCLassFound Exception (wrong name)
    791266 Explorer
    Currently Being Moderated
    DrWillett wrote:
    I've been fighting this problem for two weeks now. Everything works great until I convert to applet and try to run in a browser. I've been writing computer code since 1974 and nothing has frustrated me more than Java!

    load: class propmgmt903.class not found.
    java.lang.ClassNotFoundException: propmgmt903.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more

    or even with the class file in the same directory as the html file

    java.lang.NoClassDefFoundError: propmgmt903 (wrong name: propmgmt903/propmgmt903)
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(Unknown Source)
         at java.security.SecureClassLoader.defineClass(Unknown Source)
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)


    Any ideas......
    You should have posted your question in a new thread instead of resurrecting an old one.
    java.lang.ClassNotFoundException: propmgmt903.class
    A normal class not found usually only says that e.g. propmgmt903 can't be found, and not propmgmt903.class so it looks like you have specified the .class extension as well? Don't do that.