Java Stacktrace error Unsupported major.minor vers

2019-01-18 23:45发布

问题:

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) {}
        }
    }

}

回答1:

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!



回答2:

The problem is that your SDK and runtime environment is not matching. Try to check the compile option to use the right version, which you have for both.

See also: How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version



回答3:

If you are using Netbeans with maven and your maven-compiler-plugin has the value from properties file, then change it to literal values like 1.6 and your issue will go away. This has to do with Netbeans being confused.