如何修复 java.lang.UnsupportedClassVersionError: test (class file version 52.65535) wascompiled with preview features that are unsupported? [英] How to fix java.lang.UnsupportedClassVersionError: test (class file version 52.65535) was compiled with preview features that are unsupported?

查看:24
本文介绍了如何修复 java.lang.UnsupportedClassVersionError: test (class file version 52.65535) wascompiled with preview features that are unsupported?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 vscode 调试 java 程序时收到此错误:

I recieved this error when I trying to debug a java program with vscode:

java.lang.UnsupportedClassVersionError: 
test (class file version 52.65535) was compiled with preview features that are unsupported. 
This version of the Java Runtime only recognizes preview features for class file version 55.65535

这是launch.json:

Here is launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch) - Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
        {
            "type": "java",
            "name": "Debug (Launch)-test",
            "request": "launch",
            "mainClass": "test"
        }
    ]
}

这是java的版本:

java --version:
openjdk 11.0.2 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.2)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.2, mixed mode, sharing)

javac --version:
javac 11.0.2

这个程序可以在ubuntu原版终端上运行,但是vscode报错.

This program can run on ubuntu original terminal, but throws error in vscode.

如果你能帮我一下就好了.

it would be greatful if you can help me out.

推荐答案

更新:经过密集的谷歌搜索我想我找到了答案:

Update: after intensive googling I think I found the answer:

这是由于在 vscode 中编译的代码版本与您在系统中运行的 JDK 版本不匹配.

  1. 在您的 VScode 中,您的编译器正在尝试使用(类文件版本 52.65535)进行编译,即 Java 8,同时您的系统正在运行类文件版本 55.65535,即Java 11.在这种情况下,首先在您的系统中彻底卸载 Java 11,按照此处的卸载说明进行操作:https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A1096903

  1. In your VScode, your compiler is trying to compile using (class file version 52.65535), which is Java 8, meanwhile your system is running class file version 55.65535 which is Java 11. In this case, clean uninstall the Java 11 in your system first, follow the uninstall instructions here: https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A1096903

卸载后,从 oracle 下载并安装 JDK 8:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

After uninstallation, download and install the JDK 8 from oracle: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

重新打开你的 vscode 项目,执行以下操作:

reopen your vscode project, do the following:

打开你的launch.json文件,在配置中加入这一行:

open your launch.json file, add this line in configuration:

"vmArgs": "--enable-preview"

"vmArgs": "--enable-preview"

在要编译和运行的文件中,在 vscode 中按 F1 并执行以下操作:

inside your file your want to compile and run, press F1 in vscode and do the following:

  • Java:清理 Java 语言服务器工作区

  • Java: Clean the java language server workspace

Java:强制 Java 编译

Java: Force Java Compilation

按 F5 您的代码将编译并运行!

Press F5 your code will compile and run!

参考:https://www.baeldung.com/java-lang-unsupportedclassversion

这篇关于如何修复 java.lang.UnsupportedClassVersionError: test (class file version 52.65535) wascompiled with preview features that are unsupported?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆