Visual Studio Code - Java - 导入错误等 [英] Visual Studio Code - Java - Import Errors and More

查看:24
本文介绍了Visual Studio Code - Java - 导入错误等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚开始在工作中处理现有项目,并想使用 Visual Studio Code 作为我的 IDE(我最近将它用于一个 Rails 项目并喜欢它,所以想尝试使用 Java).

Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).

但是,每当我尝试打开其中一个项目时,都会收到大量不同的错误,包括:

However, whenever I try to open one of the projects I receive a ton of different errors including:

  • 在导入 java.io、java.util 或任何类似内容时,出现错误:

无法解析java.io(或java.util)的导入"

"The import of java.io (or java.util) cannot be resolved"

  • 现有类有错误:
  • "默认构造函数没有定义隐式超级构造函数.必须定义显式构造函数"

    "The implicit super constructor is undefined for default constructor. Must define explicit constructor"

    • 其他随机无法解析为类型"错误.
    • 所有这些似乎都源于我在使用 VS Code 时遇到的某种设置错误,但似乎可以找到它是什么.我已经卸载并重新安装了为 VS Code 启用 Java 语言的 RedHat 插件.

      All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.

      我尝试将扩展中的 java_home 设置设置为安装的直接位置,但没有奏效.尝试卸载并重新安装 java 也没有奏效.

      I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.

      我的操作规范如下:

      • 操作系统:macOS Sierra

      • OS: macOS Sierra

      VS Code 1.15.1 版

      VS Code version 1.15.1

      JDK 版本 1.8.0.144

      JDK version 1.8.0.144

      知道是什么原因造成的吗?您认为这可能是我设置 VS Code 的方式有误,还是与现有项目的设置方式有误(或不兼容)?

      Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?

      推荐答案

      我遇到了类似的问题.解决方案是从 VS Code 的工作区存储目录中删除所有内容,该目录位于 $HOME/Library/Application Support/Code/User/workspaceStorage/.

      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/.

      我在这里找到了这个解决方案:https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory

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

      更新: 从 Red Hat 0.33.0 版的 Java(TM) 语言支持开始,现在可以在 VS Code 中完成此操作.打开命令面板并输入java clean"(参见链接中的官方说明).

      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).

      这篇关于Visual Studio Code - Java - 导入错误等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆