How to fix java.lang.UnsupportedClassVersionError: test (class file version 52.65535) was compiled with preview features that are unsupported?

后端 未结 2 716
温柔的废话
温柔的废话 2020-12-11 05:26

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

java.lang.UnsupportedClassVersionError: 
test (class file version 52.65535) was comp         


        
相关标签:
2条回答
  • 2020-12-11 05:40

    In launch.json file, add "vmArgs": "--enable-preview" to your debug configuration.

    {
       ...
       "vmArgs": "--enable-preview"
    }
    
    0 讨论(0)
  • 2020-12-11 05:42

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

    This is due to a mismatch with the code version that's compiling in vscode and the JDK version you're running in your system.

    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

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

    3. reopen your vscode project, do the following:

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

      "vmArgs": "--enable-preview"

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

      • Java: Clean the java language server workspace

      • Java: Force Java Compilation

    6. Press F5 your code will compile and run!

    Reference: https://www.baeldung.com/java-lang-unsupportedclassversion

    0 讨论(0)
提交回复
热议问题