Unsupported major.minor version 52.0
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,
- Go to Maven Settings → Maven → Importing. Set the JDK for importer to 1.8.
- Go to Maven Settings → Maven → Runner. Set the JRE to 1.8.
- Go to menu File* → Project Structure → SDKs. 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 Windows → Preferences, 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:
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.
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.
user3397452
Updated on July 08, 2022Comments
-
user3397452 almost 2 years
Pictures:
Command Prompt showing versions
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 about 9 yearsyou'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 almost 9 yearsYou can use 1.8 to to compile for 1.7.
-
hnilsen about 8 yearsI got when using Build Tools 24.0.0-rcX with API 23. Should be using 23.0.2
-
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 almost 8 yearsC:\Program Files\netbeans\etc\netbeans.conf contains a netbeans_jdkhome
-
SaiyanGirl almost 8 yearsHow can you check?
-
Nixit Patel almost 8 yearswhat tools you are using for compile and running your project
-
Pallavi almost 8 yearsI 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 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 over 7 yearsThe 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 over 7 yearsNote 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 over 7 yearsI have javaHome=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home, and still getting this error.
-
Jacksonkr about 7 yearsSuch 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 about 7 yearsHow to fix this from Intellij IDEA in case I need to use 1.7? Everything works fine from command line
-
riroo almost 7 years@YuriyYunikov I have the same problem now. Please tell me if you found a way out.
-
yyunikov almost 7 years@riroo The only way to fix it for me was to downgrade to Intellij IDEA 2016.
-
Karra Max almost 7 yearsThe only thing that worked for me was: stackoverflow.com/questions/37312404/…
-
Peter Mortensen over 6 yearsWhat is "Andorra" in this context? Do you mean Android?
-
Tigerware over 5 yearsjava -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 about 4 yearsIt looks like the OP is using windows. Not sure how those instructions would work for him.