Visual Studio Code - Java - Import Errors and More

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

However, when I try to open one of the projects, I get a lot of different errors, including:

  • When importing java.io, java.util or something similar, the error is:

    "Import java.io (or java.util) cannot be allowed"

  • Existing classes have an error:

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

  • Other random "cannot resolve type errors".

All this seems to be due to some kind of configuration error that I have with VS Code, but it might seem like it is finding. I have already uninstalled and reinstalled the RedHat plugin, which allows you to use the Java language for VS Code. I tried setting the java_home parameter in the extension to the direct installation location, but this did not work. Tried to uninstall and reinstall java, and that also didn't work.

My performance is as follows

  • OS: MacOS Sierra

  • VS Code Version 1.15.1

  • JDK version 1.8.0.144

Any idea what could be causing this? Do you think that this could be a mistake in the way I created the VS-code or if its error (or rather incompatibility) with the way the existing project was created? Thanks in advance.

+27
source share
3 answers

I ran into a similar problem. The solution was to remove everything from the VS Code workspace storage directory, which was located in $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: Now this can be done from VS code with language support for Java (TM) in Red Hat version 0.33.0. Open a command palette and enter "java clean" (see the official description in the link).

+59
source

As mentioned earlier, you need to clean up the project, but this is a bit complicated thing, because each folder is Guid, and you do not know which one to clear, which requires you to delete everything. Starting from version 0.33.0 of the plugin, you can also automatically do this from the IDE, use CTRL + Shift + P and enter java clean , and the IDE will show you a hint for Java: Clear the workspace of the Java language server. After selecting, accept and restart the IDE. This will clear the language server workspace for you.

Another approach might be Maven tools in the IDE. If you have this plugin installed, you can use the sidebar and use the Maven Project Assistant options to perform actions such as cleaning, installing, packaging, etc. For example, here is my project and the parameters that it shows,

enter image description here

This can be used graphically to manage Maven-based projects. In addition, it will work with the Java Extension Pack , but is not yet sure how it will work with other extensions.

+12
source

I had to clean this folder for it to work on Windows

%APPDATA%\code\Local Storage

0
source

Source: https://habr.com/ru/post/1270976/


All Articles