Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsupported major.minor version 52.0 [duplicate]

Pictures:

Command Prompt showing versionsCommand Prompt showing versions

Picture of errorPicture 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?

like image 825
user3397452 Avatar asked Mar 18 '14 19:03

user3397452


People also ask

How do I fix Java Lang UnsupportedClassVersionError unsupported major minor version?

There are two ways to solve this problem, first make sure you run your Java program in the same or higher version of JRE, on which it has compiled, and second use the cross-compilation option to create a class file compatible to a lower JRE.

What is unsupported class version error?

Class UnsupportedClassVersionErrorThrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported.


3 Answers

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>
like image 103
Aks Avatar answered Oct 09 '22 04:10

Aks


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.

like image 33
Andrew Thompson Avatar answered Oct 09 '22 06:10

Andrew Thompson


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.

like image 64
olammy Avatar answered Oct 09 '22 05:10

olammy