Error running program: Unsupported major.minor version 52.0

Asked

Viewed 11,610 times

5

While running my program I am getting this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: TestaContador : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

These are my classes:

  • Java account.:
public class Conta {

    static int contador;

    Conta() {
        Conta.contador ++;
    }

}
  • Testacontador.java:
public class TestaContador {

    public static void main(String[] args) {
        System.out.println (" Contador : " + Conta.contador);     

        System.out.println (" Contador : " + Conta.contador);

        System.out.println (" Contador : " + Conta.contador);
    }

}
  • In what package (package) your class is located Conta ?

  • src --> (default package)

  • Moves the class Conta for the package testcontador, or creates a package with a different name.

  • The same mistake continues.

  • Apparently it was an eclipse mistake.

  • You solved the problem ?

Show 1 more comment

1 answer

8


I believe this error message means you need Java 8

  • In Eclipse I believe the path is this Window > Preferences > Java > Compiler then seek the Compiler compliance level and set to 1.8 (I believe, correct me if I’m wrong).

    I believe you can also change the value of settings in the "preferences file": org.eclipse.jdt.core.prefs.

    For example: org.eclipse.jdt.core.compiler.compliance=1.8

  • In the Intellij IDEA select project > File > Settings > Build Execution Deployment > Compiler and in Java Compiler go to target byte code and change the value to 1.8

  • If compiling via terminal or cmd, you can use target:

    javac -target 1.8 HelloWorld.java
    

I still don’t use Java8, so I’m not sure if it’s 1.8, correct me if I have confused something, it’s been a while since I work with java.

(Source: http://en.wikipedia.org/wiki/Java_class_file)

Sources:

  • 1

    This is due to build form. The java compiler has some options (in this case source and target: see details) In Ides it is common for them to configure the target for the same JDK version, so even a code being able to run in previous version will give error =/ A target 1.7 rotate FROM of it. Force a target higher than necessary hurts portability, generating unnecessary errors. Your answer solves, but why should be clear :)

  • @Brunocésar Thanks, excellent link!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.