7

Problem

When i run my HelloWorld, it returns:

"java.lang.UnsupportedClassVersionError: HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 52.65535), this version of the Java Runtime only recognizes class file versions up to 52.0 "

How do I solve this problem?

Screenshot

enter image description here

Code

public class HelloWorld{
    public static void main(String[] args) {
        System.out.println("123");
    }
}
Emma
  • 27,428
  • 11
  • 44
  • 69
rui yang
  • 71
  • 1
  • 2

2 Answers2

5

The issue is connected with Java Debugger extension. I had the same problem and it has been logged in issue log: https://github.com/Microsoft/vscode-java-debug/issues/555

Problem is only with single file applications like HelloWorld. It is ok if you run maven project.

Medsonk's instruction worked for me: https://github.com/Microsoft/vscode-java-debug/issues/555#issuecomment-478464496

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

mjuchi
  • 51
  • 2
  • Already fixed in extension **Language Support for Java(TM) by Red Hat** [link](https://marketplace.visualstudio.com/items?itemName=redhat.java) – mjuchi Apr 02 '19 at 08:24
  • 1
    Just installed the latest VSCode and Java extention, ran into the same problem; Adding "vmArgs": "--enable-preview" in launch.json > configuration, fixed the problem. – Beygi Apr 18 '19 at 13:12
-2

My situation is version conflict between java and javac on Ubuntu;
just run this code:

sudo update-alternatives --config javac
MD Mushfirat Mohaimin
  • 1,966
  • 3
  • 10
  • 22
beimuaihui
  • 25
  • 2