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 OverflowI 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).
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.
Lots of 'The import cannot be resolved' in Maven project
"The import java.util.Pair cannot be resolved"
spring - Vs Code java The import cannot be resolved - Stack Overflow
VSCode shows errors in Java source: unresolved imports
Videos
Putting the libraries in your current working directory does not work for Java, you need to add them to the classpath.
If you're using maven, that manages the classpath for you.
If not, you can manage it in VS Code by executing the Java: Configure Classpath command from the Command Palette (Ctrl+Shift+P).
You can add dependencies via Referenced libraries under the JAVA PROJECTS panel.

Or use java.project.referencedLibraries setting in settings.json.
For example:
"java.project.referencedLibraries": [
"library/**/*.jar",
"/home/username/lib/foo.jar"
]
Details can be found in configure-classpath and manage-dependencies.
I want MyUtils to work from a different Java file. Help is appreciated.
package SomeOtherPackage;
import Learning_Java1.MyUtils;<-----------also says cannont be resolved.
public class ExampleClass {
private static void doSomething() {
MyUtils.printsomejunk(87)//------------------MyUtil cannot be resolved.
}
}
Any IDE that is supposed to compile or run Java code needs to have the required classes available. In other words:
- learn what class path means in Java.
- setup your IDE to know about all the 3rd party libraries/classes you intend to use, see the corresponding documentation for example.
To add to GhostCat's answer (I am doing the same Coursera class from Princeton), this piece of information is helpful:
https://code.visualstudio.com/docs/java/java-project
Tl;dr: I had to add this to my .classpath file in the vscode project directory:
<classpathentry kind="lib" path="/path_to_stdlib.jar" />