Eclipse clean has removed most of my import statements - java

I was getting "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files" errors in all of my projects after a reboot (I run Eclipse on Windows 7). Everything was working fine before the reboot. So I tried cleaning all projects and restarting Eclipse - a few times. That didn't work so I followed some advice here and shifted
rt.jar up the list in my Windows -> Preferences -> Java -> Installed JREs. That seemed to fix the problem for all of the appcompat_v7* projects, but....
Now I find that Eclipse has rather helpfully removed most of the import statements from all of my classes. This leaves me with about 1,000 compilation errors to deal with. Is there a quick way of re-instating the required import statements, or do I really have to go to each class, each error and manually re-instate each import??

Right-click button on the project and select Source>Organize Imports.
That should work... if you have the libraries set up correctly.

Related

Trouble with importing MathParser external library in IntelliJ

as above, I cannot get access to classes of external library MathParser imported with Maven in IntelliJ. I've configured pom.xml file and enabled auto-download, so (as seen on the bottom of Project files section) it got downloaded, but when I try to use classes/import with import org.mariuszgromada.math.mxparser.*; - auto and manual import do not work.
Here's a screenshot of current situation
Any ideas?
Created new project for this test purposes, but same thing is happening. In ,,External Libraries" (in project files on the left in the screenshot) the lib appears , nevertheless no way to access to it's classes.
Update:
1) I've deleted jdk, and downloaded the newest 10'th - no results.
2) Reinstalled IntelliJ IDE couple times, same. Also I've tried to set up IntelliJ on Windows in VirtualBox (I need to finish my short project), same with jdk 10, and finally it worked. Nevertheless, I need to make it work without externalising from macOS (also, friend of mine with Mac, didn't have any similar problems). Totally same procedure, but on the macOS side on my Macbook I cannot import anything from this exterbal library (what is possible on virtualised Windows side).
3) I was trying to clean my Mac out of IntelliJ folders, then uninstall it, then imported settings from ,,healthy mac's IntelliJ" - still nothing new.
Solution:
I've reinstalled macOS, and finally that's how I've solved the problem.
Everything seems to be correct. You can try to
directly import of mxParser by changing import to import org.mariuszgromada.math.mxparser.mxParser or
check which classes you have in that package by pressing Ctrl + Space after mXparser package in import statement.

Imported project into Eclipse and shows errors right away

I'm using Eclipse Oxygen.1 release 4.7.1 and I'm running jdk and jre version 9 64-bit on a MacOS Sierra system. I imported a project downloaded from the internet and it's showing 2 errors:
1) The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project
2) The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
Has anyone ever experienced this? It must be a bug with Eclipse because all I did was import the project and it should work fine. I tried several ways to debug like clean the project and remove the JRE system library then add it again and refresh. Also tried restarting Eclipse several times and restarting my computer. Even reinstalled the JDK and re-downloaded and imported the project a few times. Any feedback would be appreciated. Thank you.
This is a rarely occurring bug in eclipse. Here are the steps to solve it, straight from this answer:
Close the project and reopen it.
Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)
OR
Delete and Re-import the project and if necessary do the above steps again.

Visual Studio Code - Java - Import Errors and More

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:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
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.
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.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
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?
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).
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.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage

Eclipse for Java shows Multiple Errors

This is my current configuration:
Eclipse IDE for Java Developers
Luna Service Release 2 (4.4.2)
Java Version 8 Update 45 Build 1.8.0_45-b15
After a time without using some Java Project folders, now Eclipse throws a lot of syntaxis errors over them:
The import javafx cannot be resolved
*** cannot be resolved to a type
The method join(String, List<String>) is undefined for the type String
The project folder never change from their location, they were error and warning free prior to left them abandoned.
I am not sure about a missing .metadata or .reccomenders or a Java version change -over no more than two months- for these projects.
What should i do to solve that?
Try cleaning your project by going to the following menu item:
Project > Clean...
If that doesn't work:
Try removing the jars from the build path and adding them again.
Double-check the jars being really on the build path (with no errors).
Make sure there is nothing in the "Problems" view.

Eclipse Galileo Java import cannot be resolve

i imported project that alredy works using SVN in eclipse , i needed to gain knowledge about that one, but unfortunetly i can't even build it. Whenever i build it i get multiple errors that are caused by
The import XXX.bl.* cannot be resolved
There are around 20 imports but only the ones from XXX.bl.* dont work. I will type you what i already tried to do:
Project -> Clean..
Adding XXX.bl in build path
Deleting and adding this imports
Changing to Java 1.6
Delete/Add JRE Library and adding Alternate JRE's
Ticking in Project Facets Java and Utility Mode (for no reason i read somewhere about it)
importing by clicking on "errored" viarable/class "import XXX.bl.*". Problem was solved but only until i Re-build/Clean project.
Closing projects, cleaning, open projects, cleaning
The weirdest thing is that when i type XXX.bl. and then click CTRL + Space it actually autofill this imports with correct names.
Im using JDK (Java EE 6 SDK Update 1 (with JDK 6 U23)).
I spent alot of time in order to search for a fix but nothing helpt so i figure out meaby if i create question here by myself and inform you what i already did you will be able to help me somehow.
Sorry for my pretty bad english, and thanks in advance!
codes are in 'sync', imports are in XXX.bl

Categories