aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes UnsupportedClassVersionError, help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

UnsupportedClassVersionError, help

Key Young
Greenhorn

Joined: Sep 18, 2006
Posts: 19
I installed the jdk 5(jdk-1_5_0_08-windows-i586-p) in my computer and set
the path variable to the bin directory and class path to MyProgram. Then I wrote a small Hello program and compiled. Compilation was successful but when I tried to run the program,I got the following :

C:\MyProgram>java MyClass
Exception in thread "main" java.lang.UnsupportedClassVersionError: MyClass (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:11
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
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:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

C:\MyProgram>

My Hello world program is as follow:

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

I don't get any error when I use jdk1.4. can someone tell me why ?
Joy Mookerji
Ranch Hand

Joined: Jul 26, 2006
Posts: 49
Did you remove the reference for your installed jdk1.4/bin from your path after modifying it to jdk1.5 ??


SCJP 5<br />Brainbench Certified in C++<br />PMP<br />Dallas,TX
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
I think your class is compiled correctly with 1.5 but its trying to run using 1.4 version. use java -version to see the java version you are dealing with and also try removing all other references(paths and classpaths) in the environment variables when you are using a particular version. Also check both your user and system paths in the environment variables.
Key Young
Greenhorn

Joined: Sep 18, 2006
Posts: 19
Thank you Praveen and Joy. I think Praveen you are right.
The only path value I have in the environment variable is version 1.5
However when I do java -version , I get version 1.3. And there is no jdk 1.3 installed in my machine at all. Anybody know how to fix it.
Please help it is very frustrated.
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

You are trying to run the class file with 1.4 version, which is being generated by 1.5 version JAVA compiler. Check your PATH variable whether it is pointing to JVM of 1.4 or 1.5.
Key Young
Greenhorn

Joined: Sep 18, 2006
Posts: 19
Hi Srinivas. Like I said in the previous post the only path value I
have is for jdk 1.5.
But this is not the most inexplicable thing I found out. My friend's
computer has only path value for version 1.4, but when I tried
java -version on his computer I got version 1.5.

The OS in my PC still see version 1.3 for some reason.
Can someone out there please lend a helping hand because this is really
annoying.
Joy Mookerji
Ranch Hand

Joined: Jul 26, 2006
Posts: 49
Whats the value of JAVA_HOME is it defined .......
do like this and test

define
JAVA_HOME=C:\jdk1.5 (environment variable)

Try to run it.......

define CLASSPATH environment variable

to some thing like this
C:\jdk150_04\lib\tools.jar;C:\jdk150_04\jre\lib\rt.jar
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
This seems to have been superceded by a new topic on the same issue...
Closing.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
Don't get me started about those stupid light bulbs.
 
subject: UnsupportedClassVersionError, help