-
2 Attachment(s)
Exception in thread "main" java.lang.NoClassDefFoundError
I'm able to compile but receiving this error when I try to execute "java apples."
Attachment 640
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.
-
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?
-
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."
-
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.
-
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.
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
-
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
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
Originally Posted by
Norm
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>
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
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
Quote:
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
-
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.
-
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.
-
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.
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
Originally Posted by
Norm
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!");
}
}
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
Here is the source
What is the name of the file containing the source?
It should be apples.java
-
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>
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
Originally Posted by
Junky
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.
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
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
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
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?
-
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Quote:
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