Search code examples
javavisual-studio-codeideadoptopenjdk

Cannot run/compile java program with VSCode


When i am hitting f5 i get this text in debug window

Error: LinkageError occurred while loading main class Hello
    java.lang.UnsupportedClassVersionError: Hello (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 56.65535

javac -version shows

javac 12

java -version

openjdk version "12" 2019-03-19
OpenJDK Runtime Environment AdoptOpenJDK (build 12+33)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 12+33, mixed mode, sharing)

Code that i am trying to compile

public class Hello {
    public static void main(String[] agrs)
    {
        System.out.println("Hello world!");
    }
}

PATH,JAVA_HOME and JRE_HOME are set properly. Debug add-on installed. I can compile and run the same code in InteliJ IDEA or using java (file), javac (file) and it will work fine but i don't know why it does not work on vscode.


Solution

  • @JornVernee send link to other question, it helped Link to question

    summary:

    1. make sure uninstall jdk8 clean
    2. install jdk11
    3. add "vmArgs": "--enable-preview" in launch.json
    4. F1, "Java: Clean ……" and "Java: Force ……"
    5. run standalone file again