gpt4 book ai didi

java.lang.UnsupportedClassVersionError : how to run code with a newer version of Java Runtime

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

命令行编译时出现错误,如何获取所需版本的Java Runtime?

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

C:\Users\s\Documents\Documents>javac hello.java

C:\Users\s\Documents\Documents>java hello
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: hello has been compiled by a more recent version of the Java Runtime (class file version 57.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)

最佳答案

看起来您使用的 JRE 与 Java 编译器不同。

java -version

javac -version 

您应该会看到版本有所不同。

一旦确认,您就可以修复导致差异的路径问题或使用 javac 设置编译目标

javac -target 1.8 hello.java

举个例子

关于java.lang.UnsupportedClassVersionError : how to run code with a newer version of Java Runtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59830152/

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