Unsupported major.minor version 52.0 [duplicate]
Asked Answered
E

26

686

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?

Ecclesia answered 18/3, 2014 at 19:40 Comment(15)
Java version mismatch. Execute using JRE 8.Majordomo
Can you please tell me what I can do? Looking at the versions provided through Command Prompt, they both seem to be 1.8.0, unless I'm completely wrong.Ecclesia
Check your browser plugin instead.Majordomo
Well that shows you've got Java 8 installed... it tells us nothing about what you're using to run the applet in your browser.Panacea
i.imgur.com/un0rQDO.png - There also doesn't seem to be an available browser plug-in version for Java 8, so am I screwed?Ecclesia
Recompile with Java 7 to match your pluginExclosure
I had no idea, but I just realized Java 8 was released todayEcclesia
I changed my PATH to JRE7 and it still shows that Java version is 1.8.0, I changed JDK to 1.7.0_51 and that worked, but JRE isn't changing to 1.7 for some reasonEcclesia
;C:\Program Files\Java\jdk1.7.0_51\bin;C:\Program Files\Java\jre7\bin - That is what I have in my PATHEcclesia
Okay I've figured it out, thanks to devnull, Jon Skeet, and Reimeus. Apparently I was using a brand new Java version (8) that just came out today and didn't have a supported version of it for Chrome browser. So I had to go back to Java 7 and recompile the code and it worked. Also, even that Java 7 was in the PATH, it was still using Java 8, so I had to uninstall Java 8 and it worked then too.Ecclesia
Just need to double check your system environment variable JDK_HOME and JRE_HOME point to JAVA 1.8 as well.Coats
So much for Java being backward compatible.Panther
Why can jdk is not able to give some descriptive comment on that its a jdk version compatibility issues kind of.Substructure
I received this error when setting up SonarQube on Windows 2016. Setup SonarQube 7.6 on Windows 2016. Installed Open JDK 1.8.201. When vNext build for analysis it would give this error. It turned out I needed to install JRE 1.8.201 and set JAVA_HOME environment variable pointing to JRE on our build server as the Analysis task was firing JAVA.exe against .jar files and it was locating it in older version folders. So directing it o use new java against its .jar files solved the issue.Anabasis
This essentially confirms the answer given in #10383429Anabasis
F
719

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>
Fifteenth answered 8/3, 2016 at 11:22 Comment(8)
"J2SE" was only used till Java 1.5 and is nowadays called "Java SE", see en.wikipedia.org/wiki/Java_Platform,_Standard_EditionEncomiast
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.Flesh
I have javaHome=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home, and still getting this error.Transmundane
How to fix this from Intellij IDEA in case I need to use 1.7? Everything works fine from command lineJoaquinajoash
@YuriyYunikov I have the same problem now. Please tell me if you found a way out.Slowdown
@Slowdown The only way to fix it for me was to downgrade to Intellij IDEA 2016.Joaquinajoash
The only thing that worked for me was: #37312904Malinowski
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?Golgi
O
90

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.

Oar answered 19/3, 2014 at 5:10 Comment(0)
E
64

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.

Eddie answered 12/11, 2014 at 15:38 Comment(0)
S
53

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.

Snelling answered 20/3, 2015 at 22:3 Comment(2)
+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.Gower
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.Nonreturnable
G
25

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.

Guyguyana answered 24/8, 2015 at 8:50 Comment(1)
It looks like the OP is using windows. Not sure how those instructions would work for him.Lenzi
T
23

I had the same problem... a JDK and plug-in version conflict.

I compiled using 1.8 ... the latest one, and that message started to appear. So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again... Now 1.8 and 1.7 in the same computer.

Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.

Thermometer answered 30/5, 2014 at 16:13 Comment(1)
You can use 1.8 to to compile for 1.7.Xenophanes
D
19

If you have a problem in Android Studio and you have installed Android N, change the Android rendering version with an older one and the problem will disappear.

Enter image description here

Deliver answered 10/3, 2016 at 12:59 Comment(1)
I got when using Build Tools 24.0.0-rcX with API 23. Should be using 23.0.2Hyperphagia
J
17

If you're using the NetBeans IDE, right click on the project and choose Properties and go to sources, and you can change the Source/Binary Format to a lower JDK version.

Enter image description here

Juli answered 16/9, 2014 at 13:52 Comment(1)
C:\Program Files\netbeans\etc\netbeans.conf contains a netbeans_jdkhomeConsensus
C
17

Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.

Read more: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html#ixzz4AVD4Evgv

Chauvin answered 3/6, 2016 at 8:19 Comment(0)
M
11

It happens when you compile your projects on higher version of java(say jdk 1.8) and then run it on a lower version (say jdk 1.7).

If you have JRE-1.7 library in your project path then ,

1.Right click on project

2.Go to Properties

3.Select Project Facets

4.Find Java in rows and then choose version (say 1.7) if using JRE-1.7

5.Click Apply and run your project.

Malefic answered 30/4, 2016 at 4:31 Comment(0)
C
11

I solved my problem by removing old versions of JRE and installing JRE 8.

Consider answered 10/7, 2016 at 11:37 Comment(0)
M
10

I could solve the same problem using the below solution.

In my project, I added a JAR file which were created in Java 8. And my project was referring to JRE 7. When I changed project JRE to 8, my problem was solved.

Steps:

In Eclipse, right click on the project name in project explorer → Build path → Libraries → click on JRE version → click EditInstalled JRE → Add → Standerd VM → select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) → provide name → Save → select same JRE for project → Finish → OK. Refresh/build project once → try to run your Java file. It should work.

Macneil answered 28/8, 2015 at 10:31 Comment(0)
H
9

I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8). Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8. Finally, problem solved.

Hedda answered 17/6, 2015 at 16:50 Comment(0)
D
6

If you are using Eclipse, make sure your menu ProjectPropertiesJava build pathlibrariesJRE system library matches your project requirements (as shown in the image).

Enter image description here

Declamation answered 20/9, 2015 at 9:9 Comment(0)
G
6

All you need to do to solve the problem is... to make sure your version of Java is the same for both compiling and running. No matter what tools or IDEs you are using.

Graze answered 6/5, 2016 at 17:53 Comment(3)
How can you check?Lai
what tools you are using for compile and running your projectGraze
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.Antiphrasis
F
5

This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.

It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.

Franci answered 11/2, 2015 at 22:32 Comment(0)
K
5

If you are using Linux and you have different versions of Java installed, use the following command:

sudo update-alternatives --config java

This will give a quick way of switching between the Java versions installed on the system. By choosing Java 8 I will solve your problem.

Kaslik answered 4/4, 2016 at 19:46 Comment(0)
F
4

If your JDK version is right. Another reason that may cause this error is that your Android Studio is in a low version, but your Gradle version is too high. Upgrade your IDE to a newer version may help this.

Fabulist answered 18/6, 2016 at 6:38 Comment(1)
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.Glutinous
S
4

Upgrade your Andorra version to JDK 1.8.

This is a version mismatch that your compiler is looking for Java version 8 and you have Java version 7.

You can run an app build in version 7 in version 8, but you can't do vice versa because when it comes to higher levels, versions are embedded with more features, enhancements rather than previous versions.

Download JDK version from this link

And set your JDK path for this

Shambles answered 1/7, 2016 at 11:49 Comment(1)
What is "Andorra" in this context? Do you mean Android?Megmega
V
3

You may want to check your Run Configurations setting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.

There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.

You can check my blog post to go through all your settings are correct.

Verse answered 15/4, 2015 at 4:0 Comment(1)
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.Birdiebirdlike
P
3

You need to use JDK 1.7.0 rather than JDK 1.8.0.

To make sure it, you need to delete JDK 1.8.0 on your computer.

If you use Mac, you need to delete:

/Library/Java/JavaVirtualMachines/jdk.jdk

/Library/PreferencePanes/JavaControlPanel.prefPane

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin

Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.

Pyromania answered 4/6, 2015 at 8:18 Comment(0)
M
1

None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8. The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.

Microeconomics answered 20/6, 2015 at 14:24 Comment(0)
P
1

If you are using IntelliJ IDEA, go to Project Structure (Ctrl + Alt + Shift + S), and you can change your project's JDK.

Passional answered 19/10, 2015 at 12:29 Comment(0)
P
1

Just want to add this. I had this problem today. Adjusted the settings in my project, rebuilt, and same problem. I had (incorrectly) assumed that changing the settings in my project (Eclipse) would cause the projects on which my project depends to be recompiled also. Adjusting the settings to all of the projects up the dependency tree solved the problem.

Priestridden answered 10/12, 2015 at 10:47 Comment(0)
T
1

I ran into this issue in Eclipse on Mac OS X v10.9 (Mavericks). I tried many answers on Stack Overflow ... finally, after a full day I *installed a fresh version of the Android SDK (and updated Eclipse, menu ProjectPropertiesAndroid to use the new path)*.

I had to get SDK updates, but only pulling down those updates I thought were necessary, avoiding APIs I were not working with (like Wear and TV) .. and that did the trick. Apparently, it seems I had corrupted my SDK somewhere along the way.

BTW .. I did see the error re-surface with one project in my workspace, but it seemed related to an import of appcompat-7, which I was not using. After rm-ing that project, so far haven't seen the issue resurface.

Terryl answered 18/3, 2016 at 5:25 Comment(0)
D
1

Just go to http://java.com/en/download/ and update your version of JRE

Dupondius answered 5/5, 2016 at 18:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.