Visual Studio Code无法处理Java。

huangapple go评论83阅读模式
英文:

Visual Studio Code Cannot Handle Java

问题

我正在尝试在VSCode中编辑Java文件,但是遇到了许多来自VSCode的错误。例如:

无法解析类型java.lang.Object。
    它是从所需的 .class 文件中间接引用的。
无法将String解析为类型
无法解析System

我尝试运行Java Clean来清理工作区,并尝试重新安装Java扩展包。但无论如何,问题仍然存在。

我无法摆脱这个问题,这真的很烦人!如果您能帮忙就太好了!谢谢。

英文:

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.

答案1

得分: 7

以下是翻译好的部分:

有关JRE出现了一些问题。在某些情况下,删除Java Language Server工作目录有助于返回到干净的状态:

> Windows - 删除 %APPDATA%\Code%USERPROFILE%\.vscode
> macOS - 删除 $HOME/Library/Application Support/Code~/.vscode
> Linux - 删除 $HOME/.config/Code~/.vscode

如果这不起作用,请尝试重置JDK并重新启动VS Code:

"java.home": "\path\to\jdk\",
"java.configuration.runtimes":[...]

参考链接:JDK设置

英文:

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

答案2

得分: 2

Molly Wang-MSFT的回答肯定是有效的,但这会导致您丢失其他已安装的VS Code扩展和用户设置。
我建议您尝试仅卸载“Extension for Java Pack”,然后重新安装它。

注意:如果您通过VS Code工作区打开了代码,请删除该工作区并重新创建。

英文:

Molly Wang-MSFT's answer will definitely work but it will cause you to lost your other VS Code installed extensions and user settings.
I will recommend you try uninstalling only "Extension for Java Pack" and reinstall it.

NOTE: If you have your codes opened via VS Code workspace, delete the workspace and recreate.

答案3

得分: 0

我在将JDK从17.05更新到17.07后遇到了这个问题。其他项目在相同的jdk设置下工作正常,其他IDE与有问题的项目使用了相同的JDK。在项目目录中检查了VS Code的设置,没有发现问题。我不太愿意采纳删除$HOME/Library/Application Support/Code的建议。

最终,我尝试重新命名了项目文件夹并重新打开了项目。神奇的是,它起效了。

英文:

I had this problem after updating the JDK from 17.05 to 17.07. Other projects worked with same jdk setting, other IDEs worked with same JDK and problematic project. Checked vscode settings in project directory, nothing wrong there. I was reluctant to follow the advice to delete $HOME/Library/Application Support/Code.

In the end, I tried renaming the project folder and reopened the project. By some magic, it worked.

huangapple
  • 本文由 发表于 2020年9月28日 22:10:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/64103869.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定