java.lang.NoClassDefFoundError

Discussion in 'Java' started by yawnmoth, Nov 28, 2005.

  1. yawnmoth

    yawnmoth Guest

    I'm recieving an Exception in thread "main"
    java.lang.NoClassDefFoundError: Test and am not really sure why. I'm
    able to compile the file - Test.java - just fine, with javac, however,
    when I try to run it, with java, I can't. The contents of Test.java
    are as follows:

    public class Test
    {
    public static void main(String[] args)
    {
    System.out.println("Hello world");
    }
    }
    yawnmoth, Nov 28, 2005
    #1
    1. Advertising

  2. yawnmoth

    Benji Guest

    yawnmoth, while chewing on bamboo shoots, wrote:
    > I'm recieving an Exception in thread "main"
    > java.lang.NoClassDefFoundError: Test and am not really sure why. I'm
    > able to compile the file - Test.java - just fine, with javac, however,
    > when I try to run it, with java, I can't. The contents of Test.java
    > are as follows:


    > public class Test
    > {
    > public static void main(String[] args)
    > {
    > System.out.println("Hello world");
    > }
    > }


    How are you trying to run it?

    I have a feeling your CLASSPATH is set to something and doesn't include ".".

    --
    Of making better designs there is no end,
    and much refactoring wearies the body.
    Benji, Nov 28, 2005
    #2
    1. Advertising

  3. yawnmoth

    IchBin Guest

    yawnmoth wrote:
    > I'm recieving an Exception in thread "main"
    > java.lang.NoClassDefFoundError: Test and am not really sure why. I'm
    > able to compile the file - Test.java - just fine, with javac, however,
    > when I try to run it, with java, I can't. The contents of Test.java
    > are as follows:
    >
    > public class Test
    > {
    > public static void main(String[] args)
    > {
    > System.out.println("Hello world");
    > }
    > }
    >

    You have to execute the class with the correct class name... Example
    there is a difference between *test* and *Test*

    *C:\java test*
    Hello world


    *C:\java Test*
    Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong
    name: test)
    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)

    --


    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA
    http://weconsultants.servebeer.com/JHackerAppManager
    __________________________________________________________________________

    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
    IchBin, Nov 28, 2005
    #3
  4. yawnmoth

    IchBin Guest

    IchBin wrote:
    > yawnmoth wrote:
    >> I'm recieving an Exception in thread "main"
    >> java.lang.NoClassDefFoundError: Test and am not really sure why. I'm
    >> able to compile the file - Test.java - just fine, with javac, however,
    >> when I try to run it, with java, I can't. The contents of Test.java
    >> are as follows:
    >>
    >> public class Test
    >> {
    >> public static void main(String[] args)
    >> {
    >> System.out.println("Hello world");
    >> }
    >> }
    >>

    > You have to execute the class with the correct class name... Example
    > there is a difference between *test* and *Test*
    >
    > *C:\java test*
    > Hello world
    >
    >
    > *C:\java Test*
    > Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong
    > name: test)
    > 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)
    >


    Sorry I forgot to mention this. Please, *as a beginner*, post your
    questions to c.l.j.help and not this group c.l.j.programmer. An look at
    you messages closer. It actually tells you what the problem is.

    --


    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA
    http://weconsultants.servebeer.com/JHackerAppManager
    __________________________________________________________________________

    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
    IchBin, Nov 28, 2005
    #4
  5. yawnmoth

    yawnmoth Guest

    IchBin wrote:
    > IchBin wrote:
    > > yawnmoth wrote:
    > >> I'm recieving an Exception in thread "main"
    > >> java.lang.NoClassDefFoundError: Test and am not really sure why. I'm
    > >> able to compile the file - Test.java - just fine, with javac, however,
    > >> when I try to run it, with java, I can't. The contents of Test.java
    > >> are as follows:
    > >>
    > >> public class Test
    > >> {
    > >> public static void main(String[] args)
    > >> {
    > >> System.out.println("Hello world");
    > >> }
    > >> }
    > >>

    > > You have to execute the class with the correct class name... Example
    > > there is a difference between *test* and *Test*

    Wouldn't java Test be correct, in this case, since the name of the
    class is Test and not test? In any case, I tried both, and recieved
    the same error for each one.

    > Sorry I forgot to mention this. Please, *as a beginner*, post your
    > questions to c.l.j.help and not this group c.l.j.programmer. An look at
    > you messages closer. It actually tells you what the problem is.

    I'll keep that in mind next time. Thanks for the tip.
    yawnmoth, Nov 28, 2005
    #5
  6. yawnmoth

    Roedy Green Guest

    On 27 Nov 2005 21:00:39 -0800, "yawnmoth" <> wrote,
    quoted or indirectly quoted someone who said :

    >Wouldn't java Test be correct, in this case, since the name of the
    >class is Test and not test? In any case, I tried both, and recieved
    >the same error for each one.


    There is no way you would get the SAME error, perhaps a similar error.
    In computing, even every comma counts. Please don't paraphrase error
    messages.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 28, 2005
    #6
  7. yawnmoth

    Pszemus Guest

    yawnmoth wrote:
    > IchBin wrote:
    >
    >>IchBin wrote:
    >>
    >>>yawnmoth wrote:
    >>>
    >>>>I'm recieving an Exception in thread "main"
    >>>>java.lang.NoClassDefFoundError: Test and am not really sure why. I'm
    >>>>able to compile the file - Test.java - just fine, with javac, however,
    >>>>when I try to run it, with java, I can't. The contents of Test.java
    >>>>are as follows:
    >>>>
    >>>>public class Test
    >>>>{
    >>>> public static void main(String[] args)
    >>>> {
    >>>> System.out.println("Hello world");
    >>>> }
    >>>>}
    >>>>
    >>>
    >>>You have to execute the class with the correct class name... Example
    >>>there is a difference between *test* and *Test*

    >
    > Wouldn't java Test be correct, in this case, since the name of the
    > class is Test and not test? In any case, I tried both, and recieved
    > the same error for each one.
    >
    >
    >>Sorry I forgot to mention this. Please, *as a beginner*, post your
    >>questions to c.l.j.help and not this group c.l.j.programmer. An look at
    >>you messages closer. It actually tells you what the problem is.

    >
    > I'll keep that in mind next time. Thanks for the tip.
    >


    Maybe it's to obvious, but worth trying for a beginner: Before
    executing (java Test), compile (javac Test.java). :)

    --
    Pszemus
    -==[ GG: 1620292 ]==-
    -==[ www: www.sarm.w.pl ]==-
    -==[ e-mail: ]==-
    Pszemus, Nov 28, 2005
    #7
  8. yawnmoth

    charlitos

    Joined:
    Nov 22, 2008
    Messages:
    1
    probably just...

    ehh you're doing everything fine so far, the only problem i see goes like this:

    javac Test.java //fine
    java Test.java //wrong

    your execution goes WITHOUT the extension

    java Test // ;)

    hope it helped buddy
    charlitos, Nov 22, 2008
    #8
  9. yawnmoth

    Banota

    Joined:
    May 23, 2012
    Messages:
    1
    جماعه بليز عندي مشكله لما بعمل run لاي برنامج على ال netbeans
    أفيدوني أفادكم الله :)

    java.lang.NoClassDefFoundError: application/Application (wrong name: Application/Application)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:472)
    Exception in thread "main" Java Result: 1
    Banota, May 23, 2012
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page