运行Java程序时出现“ JNI错误,请检查您的安装并重试”

时间:2019-07-23 05:21:53

标签: java multithreading

我正在学习Java并在Thread上尝试一些代码。我使用Thread类制作了一个程序,并且可以正常编译,但是运行该程序时出现错误。完整的错误是:

Error: A JNI error has occurred, please check your installation and
try again

Exception in thread "main"
java.lang.UnsupportedClassVersionError: Main has been compiled by a
more recent version of the Java Runtime (class file version 53.0),
this version of the Java Runtime only recognizes class file versions
up to 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)

我的线程Java文件是:

  import java.lang.Thread;

    class MyThread extends Thread
    {
        private String s;

        public MyThread(String s)
        {
            this.s = s;
        }

        public void run()
        {
            System.out.println(s);
        }
    }

我的具有主要功能的java文件是:     导入java.util.Scanner;

class Main
{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1, s2;
        System.out.print("Enter string for first thread: ");
        s1 = scanner.nextLine();
        System.out.print("Enter string for second thread: ");
        s2 = scanner.nextLine();
        MyThread t1 = new MyThread(s1);
        MyThread t2 = new MyThread(s2);
        t1.start();
        t2.start();
        scanner.close();
    }
}

我的操作系统是Windows 10 Home。我使用javac Main.java编译了文件,并尝试使用java Main运行已编译的.class文件。错误的原因是什么?我该如何预防?

1 个答案:

答案 0 :(得分:0)

java.lang.UnsupportedClassVersionError: Main has been compiled by a
more recent version of the Java Runtime (class file version 53.0),
this version of the Java Runtime only recognizes class file versions
up to 52.0"

您使用Java 9编译了代码,但尝试在Java 8 JVM上运行它。