This problem might occur if you're using an older version of Java (below 11).
To fix this:
- Open VScode and go to Preferences -> Settings
- Search java.configuration.runtimes
- Select Edit in settings.json and paste the follwing:
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "/path/to/jdk-8",
},
{
"name": "JavaSE-11",
"path": "/path/to/jdk-11",
"default": true
},
{
"name": "JavaSE-14",
"path": "/path/to/jdk-14",
},
]
- Specify the path of the JDK which you would like to use in "path:"
usually the path of JDK for macOS is
/Library/Java/JavaVirtualMachines/
- Set "default": true for that JDK
Suppose if you would like to use JDK 11, set "default": true in that code block.
Check for additional information here.
Answer from Praveen on Stack OverflowProblem with IntelliSense and Java
VS Code IntelliSense support for QuPath?
Java Intellisense doesn't work
intellisense failure
Videos
This problem might occur if you're using an older version of Java (below 11).
To fix this:
- Open VScode and go to Preferences -> Settings
- Search java.configuration.runtimes
- Select Edit in settings.json and paste the follwing:
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "/path/to/jdk-8",
},
{
"name": "JavaSE-11",
"path": "/path/to/jdk-11",
"default": true
},
{
"name": "JavaSE-14",
"path": "/path/to/jdk-14",
},
]
- Specify the path of the JDK which you would like to use in "path:"
usually the path of JDK for macOS is
/Library/Java/JavaVirtualMachines/
- Set "default": true for that JDK
Suppose if you would like to use JDK 11, set "default": true in that code block.
Check for additional information here.
Update on July 12, 2022
The Language Support for Java extension now contained a Java runtime by itself, which is used to launch the extension. That means in most cases, you don't need to specify java.home and jdt.ls.java.home.
All you need to do is use the setting java.configuration.runtimes to specify all the JDKs you have installed on your machine. Then the extension will pick the most suitable JDK according to your project's configuration.
There are two kinds of JDKs that VS Code Java will use.
I guess your problem is caused by that the Language Server cannot find a valid JDK to launch itself. (See the next paragraph about how to fix it)
The first kind is the JDK that is used to launch the Java Language Server, which requires JDK 11 or higher. And the setting
java.homeis used to specify which JDK is used to launch the Language Server. Make sure you set this setting and the Java version is >= 11.The second kind is the JDKs that is used to build/launch your project. That's controlled by the setting
java.configuration.runtimes, which is also mentioned by @Jayan Praveen's answer.
Two points first: not a native speaker and completely new to VSC.
I really like VSC but there is this one point that's a complete deal breaker for me: When I'm editing java code and want to invoke a method or a field or whatever of a self written class, intelliSense just shows the class name but when I'm typing the . or the first letters, intelliSense doesn't show anything except the inherited methods of Object. That's seriously the main reason not to use VSC.
So is there a problem with my configuration or does this simply not work with VSC?
how do i enable java auto-complete(one where it would only suggest possible keywords or methods while typing) in VSCode? i've tried installing JDK from brew, setting java.jdt.ls.java.home to the home folder of JDK, disabling/re-enabling and uninstalling/reinstalling the extensions but it still doesn't work. i watched a couple videos on youtube and all it took for them was installing the extension pack for java and the auto-complete just works right out of the box? feels like i'm missing something obvious... thanks in advance!
FIXED: The extension "Language Support for Java(TM) by Red Hat" requires version ^1.79.0 of VS Code but I was using version 1.78.0. A quick update to VS Code should fix it. I found the error by checking the runtime status of the said extension.
lol, can't believe it took me to long to fix though