Unsupported major.minor version 52.0

1,739,520

Solution 1

The issue is because of Java version mismatch. Referring to the JVM specification the following are the major versions of classfiles for use with different versions of Java. (As of now, all versions support all previous versions.)

Java SE version Major version
1.0.2 45
1.1 45 (Not a typo, same version)
1.2 46
1.3 47
1.4 48
5.0 49
6 50
7 51
8 52
9 53
10 54
11 55
12 56
13 57
14 58
15 59
16 60

These are the assigned major numbers. The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime.

Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the JDK and JRE pointed to the same version.

In IntelliJ IDEA,

  1. Go to Maven SettingsMavenImporting. Set the JDK for importer to 1.8.
  2. Go to Maven SettingsMavenRunner. Set the JRE to 1.8.
  3. Go to menu File* → Project StructureSDKs. Make sure the JDK home path is set to 1.8.

Restart IntelliJ IDEA.

Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.

Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist and replace the JVM version with:

<key>JVMVersion</key>
<string>1.8*</string>

Solution 2

The smart way to fix that problem is to compile using the latest SDK and use the cross compilation options when compiling. To use the options completely correctly requires the rt.jar of a JRE (not JDK) of the target version.

Given the nature of that applet, it looks like it could be compiled for use with Java 1.1 meaning you'd use javac -target 1.1.

Solution 3

You will need to change your compiler compliance level back to 1.7 in your IDE.

This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu WindowsPreferences, select Java, and expand it. Then select Compiler and change the compliance level to 1.7. I am sure this will work from there.

Solution 4

You must run and compile your application with the same version of Java.

If you're using Eclipse you should do 2 things:

  1. In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..." and navigate to the folder that contains the JDK.

  2. Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler" and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level" the same version that you set in the previous step.

Solution 5

You need to upgrade your Java version to Java 8.

Download latest Java archive

Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.

For 64 bit

 # cd /opt/

 # wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz"

 # tar xzf jdk-8u51-linux-x64.tar.gz

For 32 bit

 # cd /opt/

 # wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz"

  # tar xzf jdk-8u51-linux-i586.tar.gz

Note: If the above wget command doesn’t not work for you, watch this example video to download the Java source archive using the terminal.

Install Java with alternatives

After extracting the archive file, use the alternatives command to install it. The alternatives command is available in the chkconfig package.

 # cd /opt/jdk1.8.0_51/

 # alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 2

 # alternatives --config java

At this point Java 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:

 # alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_51/bin/jar 2

 # alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_51/bin/javac 2

 # alternatives --set jar /opt/jdk1.8.0_51/bin/jar

 # alternatives --set javac /opt/jdk1.8.0_51/bin/javac

Check installed Java version

Check the installed version of Java using the following command.

root@tecadmin ~# java -version

java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

Configuring Environment Variables

Most of Java-based applications use environment variables to work. Set the Java environment variables using the following commands:

Setup JAVA_HOME Variable

# export JAVA_HOME=/opt/jdk1.8.0_51
Setup JRE_HOME Variable

# export JRE_HOME=$JAVA_HOME/jre
Setup PATH Variable

# export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

Note that the change to the PATH variable put the new Java bin folders first so that they override any existing java/bins in the path. It is a bit sloppy to leave two java/bin folders in your path so you should be advised to clean those up as a separate task.

Also, put all above environment variables in the /etc/environment file for auto loading on system boot.

Share:
1,739,520
user3397452
Author by

user3397452

Updated on July 08, 2022

Comments

  • user3397452
    user3397452 almost 2 years

    Pictures:

    Command Prompt showing versions Command Prompt showing versions

    Picture of error Picture of error

    Hello.java

    import java.applet.Applet;
    import java.awt.*;
    
    public class Hello extends Applet {
    
        // Java applet to draw "Hello World"
        public void paint (Graphics page) {
            page.drawString ("Hello World!", 50, 50);
        }
    }
    

    Hello.html

    <HTML>
        <HEAD>
            <TITLE>HelloWorld Applet</TITLE>
        </HEAD>
    
        <BODY>
            <APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
            </APPLET>
        </BODY>
    </HTML>
    

    Error

    Hello : Unsupported major.minor version 52.0
    

    What may the problem be?

  • Martin Serrano
    Martin Serrano about 9 years
    you've linked to what looks like a great answer, but at stack overflow we need the details not just a link to make the answer here great.
  • m0skit0
    m0skit0 almost 9 years
    You can use 1.8 to to compile for 1.7.
  • hnilsen
    hnilsen about 8 years
    I got when using Build Tools 24.0.0-rcX with API 23. Should be using 23.0.2
  • Sk8erPeter
    Sk8erPeter about 8 years
    +1 for the 2nd step which is important, and which can also be done globally (not just project-specific) in Window > Preferences > Java > Compiler, where you need to set "Compiler compliance level" to the appropriate version.
  • Wouter
    Wouter almost 8 years
    C:\Program Files\netbeans\etc\netbeans.conf contains a netbeans_jdkhome
  • SaiyanGirl
    SaiyanGirl almost 8 years
    How can you check?
  • Nixit Patel
    Nixit Patel almost 8 years
    what tools you are using for compile and running your project
  • Pallavi
    Pallavi almost 8 years
    I am using eclipse. and i get same error. I am using java 1.7.80. I have checked everywhere, the version is same. Java 8 is not even installed on my pc.
  • Tim Büthe
    Tim Büthe over 7 years
    "J2SE" was only used till Java 1.5 and is nowadays called "Java SE", see en.wikipedia.org/wiki/Java_Platform,_Standard_Edition
  • Kieveli
    Kieveli over 7 years
    The best answer!! Oddness: I have my alternatives set to JRE 7, and build tools with JDK8. At runtime it says 'verion 52.0' unsupported. This probably means the compile target was set to java 8. Maven and I need to have words.
  • BuvinJ
    BuvinJ over 7 years
    Note that when doing step 1 here, you may or may not want to change the default JRE verse just setting it for the project.
  • IgorGanapolsky
    IgorGanapolsky over 7 years
    I have javaHome=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/‌​Contents/Home, and still getting this error.
  • Jacksonkr
    Jacksonkr about 7 years
    Such a basic idea but sometimes it's easy to get tunnel vision when you're focussing on a specific error that you don't even think to check your IDE version. Note: I was way behind and at no point did Android Studio urge me to update (1.5 > 2.3). I suspect I had suppressed upgrade warnings at some point.
  • yyunikov
    yyunikov about 7 years
    How to fix this from Intellij IDEA in case I need to use 1.7? Everything works fine from command line
  • riroo
    riroo almost 7 years
    @YuriyYunikov I have the same problem now. Please tell me if you found a way out.
  • yyunikov
    yyunikov almost 7 years
    @riroo The only way to fix it for me was to downgrade to Intellij IDEA 2016.
  • Karra Max
    Karra Max almost 7 years
    The only thing that worked for me was: stackoverflow.com/questions/37312404/…
  • Peter Mortensen
    Peter Mortensen over 6 years
    What is "Andorra" in this context? Do you mean Android?
  • Tigerware
    Tigerware over 5 years
    java -version prints out the current version. In the first picture you can see it is Java 8. Why are you saying it is running using a JDK 1.7 environment?
  • Daniel
    Daniel about 4 years
    It looks like the OP is using windows. Not sure how those instructions would work for him.