I am trying to edit Java files in VSCode, but am encountering a slew of errors from VSCode. For example:
The type java.lang.Object cannot be resolved.
It is indirectly referenced from required .class files
String cannot be resolved to a type
System cannot be resolved
I tried running Java clean to clean the workspace and have tried reinstalling the Java extension pack. Either way, the problem persisted.
I can't get rid of this and it is really annoying! Please help if you can! Thank you.
vscode/settings. json and reopen your VS Code workspace. Click F1 -> Java: Force Java compilation -> Full to rebuild the workspace. If it still doesn't work, then try F1 -> Java: Clean the Java language server workspace to clean the cache.
Visual Studio Code allows you to debug Java applications through the Debugger for Java extension. It's a lightweight Java debugger based on Java Debug Server, which extends the Language Support for Java™ by Red Hat. Here's a list of supported debugging features: Launch/Attach.
Note: If you are modifying a project that was already opened in VS Code, you may need to force clean the workspace and reload. To do so, run command Java: Clean Java Language Server Workspace.
The "Could not find or load main class" error occurs when the JVM fails to load the main class. This can happen due to various reasons, such as: The class being declared in the incorrect package. The file path of the class not matching the fully qualified name.
There's something wrong with JRE. In some occasions, deleting the Java Language Server workspace directory is helpful to go back to a clean status:
Windows - Delete
%APPDATA%\Code
and%USERPROFILE%\.vscode
.
macOS - Delete$HOME/Library/Application Support/Code
and~/.vscode
.
Linux - Delete$HOME/.config/Code
and~/.vscode
.
If this doesn't work, try to reset jdk and restart vscode:
"java.home": "\path\to\jdk\",
"java.configuration.runtimes":[...]
Reference: Setting for the JDK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With