Error while running program: Unsupported major.minor version 52.0 [closed]

5

While running my program I'm 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:

  • Conta.java :
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);
    }

}
    
asked by anonymous 13.12.2015 / 17:42

1 answer

7

I think this error message means that you need Java 8

  • In Eclipse I believe the path is this Window > Preferences > Java > Compiler then look for 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 IntelliJ IDEA select project > File > Settings > Build Execution Deployment > Compiler and Java Compiler go to target byte code and change the value to 1.8

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

    javac -target 1.8 HelloWorld.java
    

I still do not use Java8, so I'm not sure if it's 1.8, correct me if I confused something, it's been some time since I worked with java.

(Source: link )

Sources:

13.12.2015 / 19:28