Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Stacktrace error Unsupported major.minor version 51.0 [duplicate]

Possible Duplicate:
unsupported major .minor version 51.0

I made this script, and it gives me this error:

java.lang.UnsupportedClassVersionError: net/glitching/client : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    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$000(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)
Exception in thread "main" 

What does it mean? This is my code...

package net.glitching;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

public class client {

    static Socket sock = null;

    public static void main(String[] args) {
        while (true) {
            try {
                sock = new Socket("localhost", 4000);
                ObjectInputStream in = new ObjectInputStream(sock.getInputStream());
            } 
            catch (IOException ex) {}
        }
    }

}
like image 989
Daniel Gleason Avatar asked Jun 15 '12 22:06

Daniel Gleason


People also ask

How to fix Unsupported major minor version 51. 0?

Refer to this table for a list of the major version of the Java class file. To fix it, download the Java or JDK 7, and change the default JDK from 6 to 7.

What is Major Minor version in Java?

minor version error is thrown in Java when a class is compiled using a higher version of the Java Development Kit (JDK) but executed on a lower version of the Java Runtime Environment (JRE). The exact cause is printed on the version e.g. in the case of major.

What version of Java is 52?

You can see that Java 8 has major version 52, which means if you run javac command from Java 8 installation, it will by default generate a class with major version 52.

When my class encounters unsupported Classversionerror which options could resolve this issue?

1) If you encounter UnSupportedClassVersionError, check the JRE version you are using to run program and switch to higher version for quick solution.


1 Answers

Java class files compiled for Java 7 have Major/Minor versions 51/0. If you have a JVM implementation that wasn't prepared for Java 7, it would give you this error indicating "I don't know how to interpret and run this class file."

Try either compiling for an older JVM version, or upgrade your JVM.

Hope this helps!

like image 64
templatetypedef Avatar answered Oct 23 '22 12:10

templatetypedef