gpt4 book ai didi

java - JNI 错误 : A class has been compiled by a more recent version of the Java Runtime

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:05:55 28 4
gpt4 key购买 nike

我有一个包含两个类的 MyFirstProgram.java 文件。我刚刚修改了路径并尝试使用 javajavac 测试文件。

public class MyFirstProgram{
public static void main(String[] args){
System.out.println("Hello ! World :)");
}
}

但是,它返回给我:

C:\Users\antoi\Documents\Programming\Julien>java MyFirstProgram.java
Error: Could not find or load main class MyFirstProgram.java

C:\Users\antoi\Documents\Programming\Julien>javac MyFirstProgram.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

这是路径:

introducir la descripción de la imagen aquí

只有当我直接在文件夹中调用 javac 时它才有效:

C:\Users\antoi\Documents\Programming\Julien>"C:\Program Files\Java\jdk-11.0.2\bin\javac" MyFirstProgram.java

C:\Users\antoi\Documents\Programming\Julien>java MyFirstProgram
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstProgram has been compiled by a more recent version of the Java Runtime (class file version 55.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 并显示存在 UnsupportedClassVersionError。我从其他帖子了解到,我的 javac Java Runtime Environnment 可能不符合 java 命令。要执行哪些步骤才能打印 Hello World 消息?

最佳答案

因此,问题是您正在使用 javac 进行编译来自 JDK 11,然后尝试使用 Java 8 运行。由于来自 %JAVA_HOME%\bin 的 java.exe在C:\Program Files\Java\jdk-11.0.2\bin之前被取走.而且,我猜它找不到 javac因为你添加了 C:\Program Files\Java\jdk-11.0.2\bin到路径,无需重新启动 shell,这意味着路径不会重新加载。

要解决此问题,您应该删除 C:\Program Files\Java\jdk-11.0.2\bin从路径中输入,然后更新 JAVA_HOME指向 C:\Program Files\Java\jdk-11.0.2 的环境变量反而。然后重新启动您的 shell,它应该会显示 C:\Program Files\Java\jdk-11.0.2\bin。从 %JAVA_HOME%\bin 展开.

关于java - JNI 错误 : A class has been compiled by a more recent version of the Java Runtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55550802/

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