如何修复Java文件版本和编译版本在VSCode中是不同的

问题描述 投票:0回答:1

当我使用VSCode运行Java程序时,它总是显示一个错误,由于类文件版本,无法识别编译的类文件。

我检查了Mac的环境。 javac -versionjava -version展示了javac 1.8.0_181java 1.8.0_181

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

如果我运行代码,它将显示错误:

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 56.65535), this version of the Java Runtime only recognizes class file versions up to 52.0
java visual-studio-code
1个回答
0
投票
  1. 卸载jdk 8 clean(qazxsw poi)
  2. 安装jdk11(Link
  3. 在launch.json中添加“vmArgs”:“ - enable-preview”
  4. F1,“Java:清理Java语言服务器工作区”和“Java:强制Java编译”
  5. 再次运行独立文件
© www.soinside.com 2019 - 2024. All rights reserved.