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
In launch.json file, add "vmArgs": "--enable-preview" to your debug configuration.
{
...
"vmArgs": "--enable-preview"
}
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.
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
After uninstallation, download and install the JDK 8 from oracle: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
reopen your vscode project, do the following:
open your launch.json file, add this line in configuration:
"vmArgs": "--enable-preview"
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
Press F5 your code will compile and run!
Reference: https://www.baeldung.com/java-lang-unsupportedclassversion