Monday, November 16, 2009

Fix java.lang.UnsupportedClassVersionError

Today, I had a training in Java. I must start from the basic. When I compiled a *.java file with the command "javac HelloWorldApp.java", everything is OK. However, when I run the program with the command "java HelloWorldApp", I received an Error

Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorldApp (Unsupported major.minor version 50.0)

After searching in the Internet, I found the way to solve this problem. The reason is because you have compiled the *.java file with a newer javac version than the java version.

To check this, use these command:

D:\Project\JavaWorkspace>javac -version
javac 1.6.0_13

D:\Project\JavaWorkspace>java -version
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

As you can see, the java version is older than the javac version. So you check your PATH environment variable. In my case, there is a special. I have configure the java verion is 1.6.0_13. However, there is a nother program which use another java version 1.3.1. Then I moved this program to the end of the PATH value.

First value of PATH:

C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Java\jdk1.6.0_13\bin;C:\Program Files\ActivePython\\Scripts;C:\Program Files\ActivePython\;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\oracle\ora92\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\WINDOWS\system32\WindowsPowerShell\v1.0\;C:\Program Files\Oracle\jre\1.1.8\bin;

New value of PATH

C:\Program Files\Java\jdk1.6.0_13\bin;C:\Program Files\ActivePython\\Scripts;C:\Program Files\ActivePython\;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\oracle\ora92\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\WINDOWS\system32\WindowsPowerShell\v1.0\;C:\Program Files\Oracle\jre\1.1.8\bin;C:\Program Files\Oracle\jre\1.3.1\bin;

No comments:

Post a Comment