How to solve Unsupported major.minor version 49.0 or 50.0 or 51.0 (java.lang.UnsupportedClassVersionError)

       One of the very common error occurs in java program is java.lang.UnsupportedClassVersionError: class_name (Unsupported major.minor version 45.0 or 48.0 or 49.0 or 50.0 or 51.0).

You can also check the same error for your own class. I compiled the below calss in jdk1.6.0_23 // (For the whole program , visit here

class Proper1

public static String Proper(String line) throws IOException{
StringReader in = new StringReader(line);
int i=0;
char c = (char)i;

and run the Proper1.class file java version “1.4.2_16”, Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_16-b05)  and i got the below error

Exception in thread “main” java.lang.UnsupportedClassVersionError: Proper1 (Unsupported major.minor version 50.0)  ( Bad version number in .class file)

The above error comes because  the class  was compiled with Java 1.6 (major 50) but the JRE is older, such as Java 1.4 (major 48).

Now let us find out the general cause for throwing  above error.    When the JVM attempts to read a class  file that is not compatible (i.e the major and minor version number  in the class file is not supported). Java classes are forward compatible.  The error  Unsupported major.minor version 49.0 or  50.0, …  comes when the class file is compiled with higher version and run with lower version (JRE) …

Now let us see  How to troubleshoot the above error? 

Classes generated using 1.4 compiler will be loaded and executed successfully without any problems on  JRE 1.5 or 1.6 or 1.7 …(i.e. JRE version > 1.4).   Generally your classes generated by today java compilers will be compatible with future JREs (for example Java7)

To determine if the runtime Java supports the level of Java with which the program was compiled, follow these steps:

Steps :

1) Identify the class that is not supported by the JRE

2.  Check the version of Java used to compile the class file that you are trying to run (i.e class file version).

3.  Check the JRE  version of Java that is used to run the class file.   There are many ways to check the Java Runtime Environment version.

Suppose we  got the Java class file version (For eg.  major 49 & minor 0 )   and the Java runtime version (For e.g. 1.4).

Now find the equivalent class (major.minor)  version (Let us say Y)   for the JRE version     using the below mapping table

JRE Version   Major   Minor
1.1                    45          3
1.2                    46          0
1.3                    47          0
1.4                    48          0
1.5                    49          0
1.6                    50          0
1.7                    51          0

For JRE version 1.4, the equivalent major & minor  version is 48.0

and use the below condition

 If ( X is greater than Y) , then the error java.lang.UnsupportedClassVersionError : ClassName Unsupported major.minor version  X  is thrown.
where X is  class file version (major.minor)
where Y is  equivalent class file (major.minor)  version   for the Java Runtime version used

If (Y is greater than X  OR   X is equal to Y) then , the above error is not thrown. 

Now Let us see how to solve  the above problem :

1) Upgrade the JRE  to the  required version  (such that Y>X)
i)  If you are using Application Server  OR  IDE,  Please ensure that  your IDE / Application Server  version  supports the Java Runtime version required for running your classes. You can check this in
Eclipse  IDE /  WSAD 5.1 / RAD 6.0.  IDE-> Windows -> Preference ->Java -> Compiler -> Compiler Compliance Level

2) Suppose if you cannot upgrade the java runtime to the required version, then you can put  the  source code of the classs  into the target machine and recompile with the older version.

If source code use new language features  they will not be compiled by  with an earlier version of the Java

Reference :

Leave a Reply