Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: Exception in thread "main" java.lang.NoClassDefFoundError

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Exception in thread "main" java.lang.NoClassDefFoundError

    I'm able to compile but receiving this error when I try to execute "java apples."

    javaerror.jpg

    Current Variables set to:

    PATH: C:\Program Files\Java\jdk1.6.0_26\bin\
    CLASSPATH: C:\Program Files\Java\jdk1.6.0_26\jre\lib;.\;

    I think the variable settings may perhaps be the issue, any help would be appreciated.
    Attached Images Attached Images


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    This is an error? public static void main(String args[])

    Was the above post made by you? If so you were getting help (but providing very little information) in that thread why start another post in another forum?

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    No, it was not... I've already searched for a solution to my problem to no avail, which is why I have opted for direct communication. So in before "USE THE SEARCH, NOOB."

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Here are a few steps to narrow down the problem.

    Type javac -version to see if javac is recognised.
    Type java -version to see if java is recognised.
    Make sure your class apples is saved in apples.java
    Type javac apples.java
    Make sure apples.class is created
    Type java apples

    If your program still doesn't run then copy and paste everything that you did. Do not post a screenshot because:

    - It may not be visible to some forum goers (eg blocked).
    - It is hard to see.
    - If you post info here we don't have to follow a link.

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Type javac -version to see if javac is recognised.

    C:\test>javac -version
    javac 1.6.0_26

    Type java -version to see if java is recognised.

    C:\test>java -version
    java version "1.5.0_21"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_21-b01)
    Java HotSpot(TM) Client VM (build 1.5.0_21-b01, mixed mode, sharing)

    Make sure your class apples is saved in apples.java

    This didn't make any sense. The directory in the test folder includes apples.class and youtube.java. I'm using Bucky's tutorials.

    Make sure apples.class is created

    It is.

    14/06/2011 19:03 <DIR> downloads
    06/05/2011 10:43 0 FileRecovery.log
    10/04/2010 07:33 <DIR> Intel
    04/07/2011 04:47 90 LogiSetup.log
    20/07/2010 22:11 <DIR> NVIDIA
    04/07/2011 19:18 230,432 PA7302.DAT
    03/07/2011 16:24 <DIR> Program Files
    04/07/2011 22:55 <DIR> Program Files (x86)
    04/07/2011 03:37 <DIR> Python27
    16/05/2011 15:16 <DIR> red5
    27/02/2011 04:10 66,422 TDSSKiller.2.4.18.0_27.02.2011_03.10.19_log.
    txt
    27/02/2011 04:13 64,912 TDSSKiller.2.4.18.0_27.02.2011_03.12.55_log.
    txt
    20/05/2011 19:40 <DIR> temp
    04/07/2011 23:47 <DIR> test
    25/02/2011 00:20 <DIR> Users
    19/05/2011 08:14 <DIR> wamp
    04/07/2011 04:51 <DIR> Windows
    16/05/2011 14:22 <DIR> xampp
    6 File(s) 379,689 bytes
    22 Dir(s) 250,958,991,360 bytes free

    C:\>cd test

    C:\test>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\test

    04/07/2011 23:47 <DIR> .
    04/07/2011 23:47 <DIR> ..
    04/07/2011 23:50 103 youtube.java
    1 File(s) 103 bytes
    2 Dir(s) 250,958,991,360 bytes free

    C:\test>javac youtube.java

    C:\test>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\test

    04/07/2011 23:50 <DIR> .
    04/07/2011 23:50 <DIR> ..
    04/07/2011 23:50 421 apples.class
    04/07/2011 23:50 103 youtube.java
    2 File(s) 524 bytes
    2 Dir(s) 250,958,925,824 bytes free

    C:\test>java apples
    Exception in thread "main" java.lang.NoClassDefFoundError: apples

    C:\test>javac youtube.java

    C:\test>javac -classpath youtube.java
    javac: no source files
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\test>java -classpath . youtube
    Exception in thread "main" java.lang.NoClassDefFoundError: youtube

    C:\test>-classpath . youtube.java
    '-classpath' is not recognized as an internal or external command,
    operable program or batch file.

    C:\test>cdz
    'cdz' is not recognized as an internal or external command,
    operable program or batch file.

    C:\test>cd \

    C:\>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\

    01/07/2011 03:01 <DIR> 022e49ae8a3d6b3acfe91d
    03/07/2011 03:01 <DIR> 42133770d665baa30c6043
    24/06/2011 19:00 <DIR> 4513e965d5058779941cac4beac1
    19/06/2011 03:00 <DIR> 4b6788ed6aff3a6d31f70d62
    22/06/2011 03:01 <DIR> 4eaf1c73daf56f80bc4f40b250bfce
    27/06/2011 04:28 <DIR> 8567a1338ccc7405328b83c656e5
    17/05/2011 23:29 17,833 aaw7boot.log
    17/06/2011 19:01 <DIR> c598413b9ed4c428d63c40f6c18f
    29/06/2011 03:01 <DIR> c7ebce7229fd5868c950398ed177127c
    04/07/2011 10:20 <DIR> cef35608daf823fb6be7ef6d35e7d4
    14/06/2011 19:03 <DIR> downloads
    06/05/2011 10:43 0 FileRecovery.log
    10/04/2010 07:33 <DIR> Intel
    04/07/2011 04:47 90 LogiSetup.log
    20/07/2010 22:11 <DIR> NVIDIA
    04/07/2011 19:18 230,432 PA7302.DAT
    03/07/2011 16:24 <DIR> Program Files
    04/07/2011 22:55 <DIR> Program Files (x86)
    04/07/2011 03:37 <DIR> Python27
    16/05/2011 15:16 <DIR> red5
    27/02/2011 04:10 66,422 TDSSKiller.2.4.18.0_27.02.2011_03.10.19_log.
    txt
    27/02/2011 04:13 64,912 TDSSKiller.2.4.18.0_27.02.2011_03.12.55_log.
    txt
    20/05/2011 19:40 <DIR> temp
    04/07/2011 23:50 <DIR> test
    25/02/2011 00:20 <DIR> Users
    19/05/2011 08:14 <DIR> wamp
    04/07/2011 04:51 <DIR> Windows
    16/05/2011 14:22 <DIR> xampp
    6 File(s) 379,689 bytes
    22 Dir(s) 250,957,361,152 bytes free

    C:\>cd test

    C:\test>javac helloworld.java
    javac: file not found: helloworld.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\test>\ cd
    '\' is not recognized as an internal or external command,
    operable program or batch file.

    C:\test>cd \

    C:\>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\

    01/07/2011 03:01 <DIR> 022e49ae8a3d6b3acfe91d
    03/07/2011 03:01 <DIR> 42133770d665baa30c6043
    24/06/2011 19:00 <DIR> 4513e965d5058779941cac4beac1
    19/06/2011 03:00 <DIR> 4b6788ed6aff3a6d31f70d62
    22/06/2011 03:01 <DIR> 4eaf1c73daf56f80bc4f40b250bfce
    27/06/2011 04:28 <DIR> 8567a1338ccc7405328b83c656e5
    17/05/2011 23:29 17,833 aaw7boot.log
    17/06/2011 19:01 <DIR> c598413b9ed4c428d63c40f6c18f
    29/06/2011 03:01 <DIR> c7ebce7229fd5868c950398ed177127c
    04/07/2011 10:20 <DIR> cef35608daf823fb6be7ef6d35e7d4
    14/06/2011 19:03 <DIR> downloads
    06/05/2011 10:43 0 FileRecovery.log
    10/04/2010 07:33 <DIR> Intel
    04/07/2011 04:47 90 LogiSetup.log
    20/07/2010 22:11 <DIR> NVIDIA
    04/07/2011 19:18 230,432 PA7302.DAT
    03/07/2011 16:24 <DIR> Program Files
    04/07/2011 22:55 <DIR> Program Files (x86)
    04/07/2011 03:37 <DIR> Python27
    16/05/2011 15:16 <DIR> red5
    27/02/2011 04:10 66,422 TDSSKiller.2.4.18.0_27.02.2011_03.10.19_log.
    txt
    27/02/2011 04:13 64,912 TDSSKiller.2.4.18.0_27.02.2011_03.12.55_log.
    txt
    20/05/2011 19:40 <DIR> temp
    04/07/2011 23:50 <DIR> test
    25/02/2011 00:20 <DIR> Users
    19/05/2011 08:14 <DIR> wamp
    04/07/2011 04:51 <DIR> Windows
    16/05/2011 14:22 <DIR> xampp
    6 File(s) 379,689 bytes
    22 Dir(s) 250,951,446,528 bytes free

    C:\>cd test

    C:\test>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\test

    04/07/2011 23:50 <DIR> .
    04/07/2011 23:50 <DIR> ..
    05/07/2011 00:35 421 apples.class
    04/07/2011 23:50 103 youtube.java
    2 File(s) 524 bytes
    2 Dir(s) 250,951,118,848 bytes free

    C:\test>javac youtube.java

    C:\test>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\test

    04/07/2011 23:50 <DIR> .
    04/07/2011 23:50 <DIR> ..
    05/07/2011 00:48 421 apples.class
    04/07/2011 23:50 103 youtube.java
    2 File(s) 524 bytes
    2 Dir(s) 250,950,529,024 bytes free

    C:\test>java apples
    Exception in thread "main" java.lang.NoClassDefFoundError: apples

    C:\test>java apples.class
    Exception in thread "main" java.lang.NoClassDefFoundError: apples/class

    C:\test>javac -version
    javac 1.6.0_26

    C:\test>java version
    Exception in thread "main" java.lang.NoClassDefFoundError: version

    C:\test>javac apples.java
    javac: file not found: apples.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\test>java -version
    java version "1.5.0_21"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_21-b01)
    Java HotSpot(TM) Client VM (build 1.5.0_21-b01, mixed mode, sharing)

    C:\test>java -version
    java version "1.5.0_21"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_21-b01)
    Java HotSpot(TM) Client VM (build 1.5.0_21-b01, mixed mode, sharing)

    C:\test>javac apples.java
    javac: file not found: apples.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\test>cd \

    C:\>dir
    Volume in drive C is Packard Bell


    Directory of C:\

    01/07/2011 03:01 <DIR> 022e49ae8a3d6b3acfe91d
    03/07/2011 03:01 <DIR> 42133770d665baa30c6043
    24/06/2011 19:00 <DIR> 4513e965d5058779941cac4beac1
    19/06/2011 03:00 <DIR> 4b6788ed6aff3a6d31f70d62
    22/06/2011 03:01 <DIR> 4eaf1c73daf56f80bc4f40b250bfce
    27/06/2011 04:28 <DIR> 8567a1338ccc7405328b83c656e5
    17/05/2011 23:29 17,833 aaw7boot.log
    17/06/2011 19:01 <DIR> c598413b9ed4c428d63c40f6c18f
    29/06/2011 03:01 <DIR> c7ebce7229fd5868c950398ed177127c
    04/07/2011 10:20 <DIR> cef35608daf823fb6be7ef6d35e7d4
    14/06/2011 19:03 <DIR> downloads
    06/05/2011 10:43 0 FileRecovery.log
    10/04/2010 07:33 <DIR> Intel
    04/07/2011 04:47 90 LogiSetup.log
    20/07/2010 22:11 <DIR> NVIDIA
    04/07/2011 19:18 230,432 PA7302.DAT
    03/07/2011 16:24 <DIR> Program Files
    04/07/2011 22:55 <DIR> Program Files (x86)
    04/07/2011 03:37 <DIR> Python27
    16/05/2011 15:16 <DIR> red5
    27/02/2011 04:10 66,422 TDSSKiller.2.4.18.0_27.02.2011_03.10.19_log.
    txt
    27/02/2011 04:13 64,912 TDSSKiller.2.4.18.0_27.02.2011_03.12.55_log.
    txt
    20/05/2011 19:40 <DIR> temp
    04/07/2011 23:50 <DIR> test
    25/02/2011 00:20 <DIR> Users
    19/05/2011 08:14 <DIR> wamp
    04/07/2011 04:51 <DIR> Windows
    16/05/2011 14:22 <DIR> xampp
    6 File(s) 379,689 bytes
    22 Dir(s) 250,942,435,328 bytes free

    C:\>cd test

    C:\test>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\test

    04/07/2011 23:50 <DIR> .
    04/07/2011 23:50 <DIR> ..
    05/07/2011 00:48 421 apples.class
    04/07/2011 23:50 103 youtube.java
    2 File(s) 524 bytes
    2 Dir(s) 250,942,435,328 bytes free

    C:\test>javac youtube.java

    C:\test>javac apples.java
    javac: file not found: apples.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\test>javac apples.class
    javac: invalid flag: apples.class
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\test>java apples
    Exception in thread "main" java.lang.NoClassDefFoundError: apples

    C:\test>

    I'm fairly sure the problem is the PATH/CLASSPATH. Sorry if I didn't provide enough information, here.

  6. #6
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError


  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    That doesn't make any sense.
    There is a java command.
    There is an apples.class file.

    It's like there is a batch file named java.bat that is sidetracking the attempt to execute the real java.exe command. To test that Try entering: java.exe apples

  8. #8
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Quote Originally Posted by Norm View Post
    To test that Try entering: java.exe apples
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\owner>java.exe apples
    Exception in thread "main" java.lang.NoClassDefFoundError: apples

    C:\Users\owner>cd \

    C:\>dir
    Volume in drive C is Packard Bell


    Directory of C:\

    01/07/2011 03:01 <DIR> 022e49ae8a3d6b3acfe91d
    03/07/2011 03:01 <DIR> 42133770d665baa30c6043
    24/06/2011 19:00 <DIR> 4513e965d5058779941cac4beac1
    19/06/2011 03:00 <DIR> 4b6788ed6aff3a6d31f70d62
    22/06/2011 03:01 <DIR> 4eaf1c73daf56f80bc4f40b250bfce
    27/06/2011 04:28 <DIR> 8567a1338ccc7405328b83c656e5
    17/05/2011 23:29 17,833 aaw7boot.log
    17/06/2011 19:01 <DIR> c598413b9ed4c428d63c40f6c18f
    29/06/2011 03:01 <DIR> c7ebce7229fd5868c950398ed177127c
    04/07/2011 10:20 <DIR> cef35608daf823fb6be7ef6d35e7d4
    14/06/2011 19:03 <DIR> downloads
    06/05/2011 10:43 0 FileRecovery.log
    10/04/2010 07:33 <DIR> Intel
    04/07/2011 04:47 90 LogiSetup.log
    20/07/2010 22:11 <DIR> NVIDIA
    04/07/2011 19:18 230,432 PA7302.DAT
    03/07/2011 16:24 <DIR> Program Files
    04/07/2011 22:55 <DIR> Program Files (x86)
    04/07/2011 03:37 <DIR> Python27
    16/05/2011 15:16 <DIR> red5
    27/02/2011 04:10 66,422 TDSSKiller.2.4.18.0_27.02.2011_03.10.19_log.
    txt
    27/02/2011 04:13 64,912 TDSSKiller.2.4.18.0_27.02.2011_03.12.55_log.
    txt
    20/05/2011 19:40 <DIR> temp
    04/07/2011 23:50 <DIR> test
    25/02/2011 00:20 <DIR> Users
    19/05/2011 08:14 <DIR> wamp
    04/07/2011 04:51 <DIR> Windows
    16/05/2011 14:22 <DIR> xampp
    6 File(s) 379,689 bytes
    22 Dir(s) 250,947,039,232 bytes free

    C:\>cd test

    C:\test>dir
    Volume in drive C is Packard Bell


    Directory of C:\test

    04/07/2011 23:50 <DIR> .
    04/07/2011 23:50 <DIR> ..
    05/07/2011 01:52 421 apples.class
    04/07/2011 23:50 103 youtube.java
    2 File(s) 524 bytes
    2 Dir(s) 250,947,039,232 bytes free

    C:\test>javac youtube.java

    C:\test>java.exe apples
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
    umber in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n 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)

    C:\test>

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    java.exe apples
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
    Now the java.exe command found the .class file.
    It looks like the java.exe command is an older version of java than the java command that created the .class file.
    Or the .class file is corrupted.
    Here is the error message I get when I compile with 6_25 and execute with 1.4
    java.lang.UnsupportedClassVersionError: TicTacToe (Unsupported major.minor version 50.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    ...
    Do you have a hex editor? Look at the first few bytes of the .class file.
    Here is what I see for the above .class file:
    CAFEBABE0000003200BF0A0039007207
    Last edited by Norm; July 4th, 2011 at 08:21 PM. Reason: 6_25 not 6_26

  10. #10
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    I don't have a hex editor, no. I've only just started attempting to teach myself Java today. Could you recommend one? Also, what is your PATH and CLASSPATH variables set to? Could you please provide an example.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    The OS is finding the javac and java commands.
    Your last post shows that the java command found a problem with the .class file.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Is the apples class defined in the youtube.java file?
    Normally the file names of the .java and the .class files are the same.

  13. #13
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Quote Originally Posted by Norm View Post
    Is the apples class defined in the youtube.java file?
    Normally the file names of the .java and the .class files are the same.
    What do you mean by this, sorry? You'll have to forgive me as I've only just started learning Java today. Here is the source if that's what you were asking:

    class apples{
    public static void main(String args[]){
    System.out.println("Hello youtube!");
    }
    }

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Here is the source
    What is the name of the file containing the source?
    It should be apples.java

  15. #15
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    This is what happened when I tried to compile then execute after doing what you just said.

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\owner>java.exe apples
    Exception in thread "main" java.lang.NoClassDefFoundError: apples

    C:\Users\owner>cd \

    C:\>dir
    Volume in drive C is Packard Bell


    Directory of C:\

    01/07/2011 03:01 <DIR> 022e49ae8a3d6b3acfe91d
    03/07/2011 03:01 <DIR> 42133770d665baa30c6043
    24/06/2011 19:00 <DIR> 4513e965d5058779941cac4beac1
    19/06/2011 03:00 <DIR> 4b6788ed6aff3a6d31f70d62
    22/06/2011 03:01 <DIR> 4eaf1c73daf56f80bc4f40b250bfce
    27/06/2011 04:28 <DIR> 8567a1338ccc7405328b83c656e5
    17/05/2011 23:29 17,833 aaw7boot.log
    17/06/2011 19:01 <DIR> c598413b9ed4c428d63c40f6c18f
    29/06/2011 03:01 <DIR> c7ebce7229fd5868c950398ed177127c
    04/07/2011 10:20 <DIR> cef35608daf823fb6be7ef6d35e7d4
    14/06/2011 19:03 <DIR> downloads
    06/05/2011 10:43 0 FileRecovery.log
    10/04/2010 07:33 <DIR> Intel
    04/07/2011 04:47 90 LogiSetup.log
    20/07/2010 22:11 <DIR> NVIDIA
    04/07/2011 19:18 230,432 PA7302.DAT
    03/07/2011 16:24 <DIR> Program Files
    04/07/2011 22:55 <DIR> Program Files (x86)
    04/07/2011 03:37 <DIR> Python27
    16/05/2011 15:16 <DIR> red5
    27/02/2011 04:10 66,422 TDSSKiller.2.4.18.0_27.02.2011_03.10.19_log.
    txt
    27/02/2011 04:13 64,912 TDSSKiller.2.4.18.0_27.02.2011_03.12.55_log.
    txt
    20/05/2011 19:40 <DIR> temp
    04/07/2011 23:50 <DIR> test
    25/02/2011 00:20 <DIR> Users
    19/05/2011 08:14 <DIR> wamp
    04/07/2011 04:51 <DIR> Windows
    16/05/2011 14:22 <DIR> xampp
    6 File(s) 379,689 bytes
    22 Dir(s) 250,947,039,232 bytes free

    C:\>cd test

    C:\test>dir
    Volume in drive C is Packard Bell


    Directory of C:\test

    04/07/2011 23:50 <DIR> .
    04/07/2011 23:50 <DIR> ..
    05/07/2011 01:52 421 apples.class
    04/07/2011 23:50 103 youtube.java
    2 File(s) 524 bytes
    2 Dir(s) 250,947,039,232 bytes free

    C:\test>javac youtube.java

    C:\test>java.exe apples
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
    umber in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n 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)

    C:\test>java.exe apples
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
    umber in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n 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)

    C:\test>javac apples.java

    C:\test>javac apples.java

    C:\test>dir
    Volume in drive C is Packard Bell
    Volume Serial Number is B2CF-015B

    Directory of C:\test

    05/07/2011 03:08 <DIR> .
    05/07/2011 03:08 <DIR> ..
    05/07/2011 03:09 420 apples.class
    04/07/2011 23:50 103 apples.java
    2 File(s) 523 bytes
    2 Dir(s) 250,842,640,384 bytes free

    C:\test>javac apples.class
    javac: invalid flag: apples.class
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\test>javac apples.java

    C:\test>javac apples.java

    C:\test>java apples
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
    umber in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n 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)

    C:\test>
    Last edited by Scarice; July 4th, 2011 at 09:15 PM.

  16. #16
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    You have a class inside youtube.java. When you compile it, the apple.class file is generated. As I said the apple class should be in apple.java not youtube.java. I also noted that your JRE is 1.5 while the JDK is 1.6. You will need to remove 1.5 from the path and only have 1.6 as 1.5 cannot run classes generated in 1.6.

  17. #17
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Out of curiosity post the contents of youtube.java

    Arrgh, fell for the ol' page 2 trick.

  18. #18
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Please ask questions on the forum!

    You have JRE 1.5 installed as well as JDK 1.6. Since the JDK comes with the JRE all you need to do is remove JRE 1.5 from your path and JDK/JRE 1.6 will be found instead. You can delete/uninstall 1.5 if you like but it is not necessary.

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    The JRE install was different. On Windows the java.exe command is copied to the C:\WINDOWS\system32\ folder, which is on the PATH. Also there are registry entries that point to stuff.
    Look in the above mentioned folder and see what version of java.exe is there.Right click and properties and version and file version should show you.

  20. #20
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    The strange thing is that even if class apples is in youtube.java, compiling youtube.java generates apples.class which should run. I just wonder if OP is yanking our chain.

  21. #21
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    The path variable is set to 1.6 (C:\Program Files\Java\jdk1.6.0_26\bin\).

    The version of the Java.exe in the system32 folder is 6.0.260.3. I'll try a fresh install of everything, I suppose.

  22. #22
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Quote Originally Posted by Junky View Post
    The strange thing is that even if class apples is in youtube.java, compiling youtube.java generates apples.class which should run. I just wonder if OP is yanking our chain.
    If only, I'm highly irritated as of now due to this issue.

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    java apples
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    This shows something. The message is different for my using 1.4 vs his 1.5

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    C:\test>java -version
    java version "1.5.0_21"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_21-b01)
    Java HotSpot(TM) Client VM (build 1.5.0_21-b01, mixed mode, sharing)
    If you see 6.0.260.3 in the system32 folder, where did the above output come from?
    Do you get a different response for java vs java.exe?

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError

    Running: C:\Program Files\Java\jdk1.5.0_04\bin\java.exe -cp D:\JavaDevelopment\Testing\ForumQuestions6\ TicTacToe

    java.lang.UnsupportedClassVersionError: Bad version number in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :620)
    I found a 1.5 version of the java.exe file. The error message is the same as what the OP sees.

    Uninstall the 1.5 and install a 1.6

Page 1 of 2 12 LastLast

Similar Threads

  1. Exception in thread "main" java.lang.NullPointerException
    By MryJaho in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 4th, 2011, 05:36 PM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. Replies: 13
    Last Post: October 13th, 2010, 11:20 AM
  4. Replies: 2
    Last Post: March 26th, 2010, 11:22 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 11:54 AM