I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.

I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory

Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).

Answer from toreyhickman on Stack Overflow
Top answer
1 of 13
243

I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.

I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory

Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).

2 of 13
47

As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.

Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,

That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.

🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 366
The Import Cannot Be Resolved, IntelliJ and VS Code · Issue #366 · redhat-developer/vscode-java
November 14, 2017 - I'm getting an issue The import com.[company name].taskservice cannot be resolved on a project. I was getting this issue first and then I ran a mvn idea:idea and it resolved the dependencies. I...
Author   redhat-developer
Discussions

Lots of 'The import cannot be resolved' in Maven project
Issue Type: Bug I have a Maven project with some dependencies. Sometimes VSC looses track of these dependencies and can no longer identify the packages in them. Either when opening the workspace or later on. When I open the class that ha... More on github.com
🌐 github.com
11
July 9, 2021
"The import java.util.Pair cannot be resolved"
So anyway, I don't really want to be that guy who's wasting his time solving weird bugs from the IDEs while the other does most of the actual coding (already had problems with getting vscode to recognize JDK then getting IntelliJ to recognize the files correctly) ... JDK version: 17 (I guess? It's the latest version (downloaded it yesterday) and the file ends in _17_35.msi) ... Find the file with 8 problems (all linked to that import) and look at line 4 (import java... More on github.com
🌐 github.com
3
October 26, 2021
spring - Vs Code java The import cannot be resolved - Stack Overflow
I recently moved from windows 10 to Ubuntu 16.04, I'm a java developer, when I was on windows I installed Vs Code with the java Extension pack. On windows I never Had problem to make my daily work,... More on stackoverflow.com
🌐 stackoverflow.com
VSCode shows errors in Java source: unresolved imports
Java symbols will not be available.. However, I do have Java source code. What is more, VSCode's Java extension launches a task - Java build. The result is that I now have many import cannot be resolved errors. More on github.com
🌐 github.com
1
1
🌐
GitHub
github.com › microsoft › vscode-java-pack › issues › 685
Lots of 'The import cannot be resolved' in Maven project · Issue #685 · microsoft/vscode-java-pack
July 9, 2021 - I have a Maven project with some dependencies. Sometimes VSC looses track of these dependencies and can no longer identify the packages in them. Either when opening the workspace or later on. When I open the class that have those imports, VSC is able to resolve all.
Author   microsoft
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 2182
"The import java.util.Pair cannot be resolved" · Issue #2182 · redhat-developer/vscode-java
October 26, 2021 - So anyway, I don't really want to be that guy who's wasting his time solving weird bugs from the IDEs while the other does most of the actual coding (already had problems with getting vscode to recognize JDK then getting IntelliJ to recognize the files correctly) ... JDK version: 17 (I guess? It's the latest version (downloaded it yesterday) and the file ends in _17_35.msi) ... Find the file with 8 problems (all linked to that import) and look at line 4 (import java.util.Pair;)
Author   redhat-developer
🌐
Stack Overflow
stackoverflow.com › questions › 59739067 › vs-code-java-the-import-cannot-be-resolved
spring - Vs Code java The import cannot be resolved - Stack Overflow
6 The import org.springframework cannot be resolved - Java(268435846) 4 VSCode can not import external libraries · 1 VS code cannot read java file · 2 VS Code Cannot Detect Java Libraries · 2 The declared package "" does not match the expected package "(file name)" 6 VSCode won't import java.awt packages ·
Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-project
Managing Java Projects in VS Code
November 3, 2021 - Lightweight mode doesn't resolve imported dependencies nor build the project, so it does not support running, debugging, refactoring, linting, or detecting semantic errors. For these features to be available, you need to switch your workspace from lightweight mode to standard mode. You can control which mode to launch with by configuring java.server.launchMode with the options below:
🌐
Chief Delphi
chiefdelphi.com › technical › programming
Imports not working on VSCode - Programming - Chief Delphi
September 19, 2019 - Some examples are: · What’s the exact error message you’re getting · Make sure that you are using the WPILib version of vscode and not just regular vscode. I had the same issues for some reason
🌐
GitHub
github.com › microsoft › vscode-java-pack › issues › 973
The import cannot be resolved · Issue #973 · microsoft/vscode-java-pack
April 18, 2022 - As shown in the figure, it is prompted that this package cannot be imported, but for the same project, there is no similar prompt in the idea, and the package compile of the project itself is fine,...
Author   microsoft
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 1804
Import cannot be resolved but exist in JAR? · Issue #1804 · redhat-developer/vscode-java
February 10, 2021 - Hi everyone, when I do import ... The import com.mypackage.abcde cannot be resolved Java(268435846). In my project's .code-workspace file, under "java.project.referencedLibraries" I have the entry "/path/to/my/jar-1.0.jar". When I open the jar file with vim, I see that com/mypackage/abcde/ForecastRequestV1.class is inside. Does anyone know how I can go about debugging why VSCode is complaining ...
Author   redhat-developer
🌐
javathinking
javathinking.com › blog › visual-studio-code-java-import-errors-and-more
How to Fix Visual Studio Code Java Import Errors: Resolving java.io, java.util, Implicit Super Constructor & 'Cannot Resolve to a Type' Issues in Existing Projects — javathinking.com
The error "Xyz cannot be resolved to a type" indicates VS Code cannot find the class Xyz. This affects both custom classes and third-party libraries. Java requires classes to reside in folders matching their package names.
🌐
javathinking
javathinking.com › blog › visual-studio-code-cannot-handle-java
How to Fix 'java.lang.Object Cannot Be Resolved' and Other Java Errors in Visual Studio Code — javathinking.com
However, even experienced developers can encounter frustrating errors like java.lang.Object cannot be resolved or "The import java.util cannot be resolved." These issues often stem from misconfigurations, missing dependencies, or incorrect setup of the Java Development Kit (JDK) or VS Code extensions.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2375
Error in VSCode: Import "java.util" could not be resolved Pylance (reportMissingImports) · Issue #2375 · microsoft/pylance-release
February 11, 2022 - I'm trying to write a Burp extension in Visual Studio Code and I'm getting a pylance error: Import "java.util" could not be resolvedPylance. I found some suggestions that I should try to clean the Java Language Server Workspace, but when I try running that command in VSCode, I get another error: ...
Author   microsoft
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 284
Can't resolve imports on an Eclipse project · Issue #284 · redhat-developer/vscode-java
Unable to acquire the state change lock for the module: osgi.identity; type="osgi.bundle"; version:Version="1.8.1.20170728-1531"; osgi.identity="org.eclipse.m2e.core"; singleton:="true" [id=52] STARTED [STARTED] org.osgi.framework.BundleException: Unable to acquire the state change lock for the module: osgi.identity; type="osgi.bundle"; version:Version="1.8.1.20170728-1531"; osgi.identity="org.eclipse.m2e.core"; singleton:="true" [id=52] STARTED [STARTED] at org.eclipse.osgi.container.Module.lockStateChange(Module.java:337) at org.eclipse.osgi.container.Module.start(Module.java:401) at org.ecl
Author   redhat-developer
🌐
GitHub
github.com › Microsoft › vscode-java-test › issues › 616
Packages cannot be resolved · Issue #616 · microsoft/vscode-java-test
February 15, 2019 - Enviroment macOS Mojave 10.14.3 Visual Studio Code 1.31.1 Java Test Runner 0.14.0 issue I want to use jUnit 5 on VSCode so I use Java Test Runner. However after installation console display errors saying can not be resolved for jUnit5. H...
Author   microsoft
🌐
Reddit
reddit.com › r/learnpython › vscode saying import could not be resolved but it definitely is
r/learnpython on Reddit: vscode saying import could not be resolved but it definitely is
July 9, 2021 - I am running a python script from the command line (cmd) that is in a directory in the system PATH environment variable, and so it is able to import a module in that same directory. But I guess vscode doesn't know I'll be running the script there.