Exactly, Both fixes should work, but sometimes the issue is actually that VS Code is using the wrong Java runtime, even when you’ve installed the correct JDK. If you’ve already updated the JDK but are still seeing the error, you might want to check which version VS Code is actually using.
Try this:
- Press Ctrl + Shift + P and search for “Java: Configure Runtime”.
- Select your installed JDK from the list.
Also, double-check your JAVA_HOME environment variable, which could still be pointing to an older JDK. Open a terminal and run:
echo %JAVA_HOME% # Windows
echo $JAVA_HOME # macOS/Linux
If it’s not pointing to your updated JDK, change it like this:
export JAVA_HOME=/path/to/your/jdk
Then restart VS Code. Lastly, make sure your VS Code project is configured to use the right compiler version by adding this to your .vscode/settings.json file:
"java.configuration.runtimes": [
{
"name": "JavaSE-17",
"path": "/path/to/jdk-17",
"default": true
}
]
This will ensure that VS Code doesn’t default to an older Java version, and you won’t see the this version of the java runtime only recognizes class file versions up to 52.0 error anymore."