gpt4 book ai didi

java - "A JNI error has occurred, please check your installation and try again"运行java程序

转载 作者:行者123 更新时间:2023-12-02 09:40:02 26 4
gpt4 key购买 nike

我正在学习 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 家庭版。我使用 javac Main.java 编译了该文件并尝试使用 java Main 运行已编译的 .class 文件。错误的原因是什么?我该如何预防?

最佳答案

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 上运行它。

关于java - "A JNI error has occurred, please check your installation and try again"运行java程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57157156/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com