Eclipse/Java newbie: package not found now, but it was yesterday - java

I'll be involved in Java development for the first time. The application will be built on an set of Eclipse plug-ins and packages called UDOP. This set comes with tutorials, which I'm going through.
Yesterday things were fine, and in my example code I was able to import a certain package, and extend one of the classes it contains. When I started Eclipse today, a package in an import statement has a red line under it, with a hover-message telling me that the import cannot be resolved. The target platform is correct, and my dependencies match what the tutorial wants. I've run Update Classpath.
Details:
the import statement is
import com.tdkc.udop.extensionpoints.views.ViewPartBase;
The red squiggly line is under com.tdkc.udop.extensionpoints.
com.tdkc.udop is set as a dependency.
The Target Platform is .../UDOP_SDK,
and under that I can find the file .../UDOP_SDK/plugins/com.tdkc.udop_1.7.0/com/tdkc/udop/extensionpoints/views/ViewPartBase.class
com.tdkc.udop appears in the Package Explorer, and from within the P.E. I can navigate down and see ViewBasePart.class.
Although I'm new at Eclipse and Java, I do have moderate experience with c++ and Objective-C and Cocoa.
What are possible causes for an import not to be found? What should I check? Thanks.

If nothing has changed since the last time everything was peachy, it might just be a matter of doing a Project -> Clean and then selecting Clean all projects like so:
Finally, click on OK and Eclipse should clean out all the projects and build everything.

On the project in question (Left side of Eclipse in "Package Explorer"), right click on the project name and select "Build Path" > "Configure Build Path...".
On the left side, select "Java Build Path", then the tab "Libraries". From there, "Add JARs..." and point to the JAR file that contains your class. From there try and build/clean.

If that import statement is what you've used, the syntax is wrong. It should be:
import com.tdkc.udop.extensionpoints.views.ViewPartBase;

Move your cursor to the error line(com.tdkc.udop.extensionpoints. in your case) then Eclipse will show you the list from which you can get rid of that error. Scroll down find Fix Project Setup and then Eclipse will suggest jar files which can be added to solve dependency problem. add those dependency by clicking OK.
and error will disappear.

Related

IntelliJ does not recognize certain Spring packages

In my rest API projects, IntelliJ suddenly stopped recognizing imports from the packages org.springframework.http and org.springframework.web. For example, it gives me the red squiggleys when I try to create an instance of ResponseEntity or use the #RestController annotation. I also get the red squiggleys under the corresponding import statements with the message “Cannot resolve symbol” when I hover my cursor over them.
I click the light bulb and select “add Maven dependency”, but IntelliJ cannot find any to add. Even if it could, the proper Maven dependencies are already present in the pom.xml, but they are grayed-out as if they aren’t referenced anywhere. Manually specifying different versions of the dependencies does nothing. Reimporting the project does nothing. Cloning the repo again and starting a new project didn’t help. Neither did invalidating the caches, deleting the entire .m2 directory, updating IntelliJ, restarting my machine, or fiddling with the interpreter.
The code builds and runs as expected without any problems both in terminal and in the IDE. I have no idea why the IntelliJ seems so confused. This is only happening on my machine, and I can’t think of anything I could have done to cause it. Nobody else on the team has seen this issue. It’s not isolated to any particular repo. It happens any time I try to import from these specific packages. It’s been bugging me all week, and my teammates are just as bewildered as I am. Any suggestions?
Additional Info:
Java 11.0.6
Latest versions of Maven and IntelliJ
macOS Mojave
Update
I decided to once again delete my entire .m2 directory and the .idea directory for my project. I have done this multiple times over the past week with no results. This time, when I reimported the project I found the aforementioned org.springframework.web and org.springframework.http imports are now being recognized correctly. However, IntelliJ is now failing to recognize some of the other imports, such as lombok.
I actually had this particular version of the problem last week for several hours. I then took a short break and opened my laptop to find that everything was magically back to normal. A few days later, I started having the error that I described above. These unrecognized imports seem to appear and disappear at random, regardless of the project I am working in or any changes to the code.
Let me reiterate that there is nothing wrong with the code. IntelliJ builds and runs it flawlessly, even with all the red squiggleys. There is something wonky going on with the editor. I have included a screenshot below of the current state.
Solved
I decided to uninstall and reinstall IntelliJ. which resolved the issue.
This can happen for lots of reasons:
Try the following:
(Mac users) Right click on the project -> Maven -> reimport
If that doesn't work:
Delete `.idea` folder and re import the project.
Its located in the root of the project. like this one
za$ ls .idea/
.name compiler.xml encodings.xml httpRequests/ misc.xml vcs.xml workspace.xml
If that doesn't work, make sure the jar is loaded and you can see it listed as a dependency, or import it manually. see this questions:
https://stackoverflow.com/questions/1051640/correct-way-to-add-external-jars-lib-jar-to-an-intellij-idea-project
If that doesn't work:
Delete all versions of the jar(that having the issue) from ./m2
folder. Or make sure to specify a specific version in pom.xml
Refer to the image link here Exclude from import and Completion
In Intellij settings File-> Settings, go to Editor -> General -> Auto Import -> Java section -> Exclude from import and completion. Remove those classes you have accidentally put there. It might have ever happened coz you have ever pressed the wrong button when there is an auto-suggest from Intellij.
Actually, I have the same problem a few days ago. And that is how I resolved it.

All my lines of code in my 'src' folder have errors in Eclipse

Am having problems with development in android as all my lines of code in all the files in the src folder where am placing my java files have errors on them. I do not know where the problem is coming from!
First had problems where 'R' was underlined in red. then after Ctrl+Shift+O, I exited my eclipse and on opening it, that's what I saw on my java files
Go to
Project Properties>Java Build Path>Libraries tab
and make sure JRE is added, if not, click "Add Library..." and add it.
All errors seems related to Android's specific classes:
you may have a problem with you Eclipse+ADT installation
you may have pasted the code into the wrong type of project
you may simple missing the corrisponding import
Last is simplier to verify, just hover with mouse over the error and see if Eclipse suggests you to add a specific import

Build path problems with sdk

I just downloaded the Android SDK and the plugin but when I try to create a project it automatically makes a library for the support and my project that I created has errors. Here is what I mean:
This is after I clean up the projects [Project -> Clean]
Additionally, R does not work (even when I import it) :
This is all with a clean project. I would appreciate it if you could help me.
Note: I know there are similar questions out there, but I could not get it working.
I think I need to import the appcompat package again, but I do not know where to locate it.
The error the container "Android Dependencies references non existing library" probably means your build path isn't pointing to any jar file. I recommend checking your build path:
Right click and choose 'build path'
Click on 'Android'. Make sure app_compact appears under the library target. If it does not click 'add' under library to add it.

Eclipse - Android Project from existing Code does not work

i'm trying to import a folder with an existing project in Eclipse, but it wont't work.
CTRL + N --> Android Project from existing code --> give folder directory --> Finish
Once i try that, nothing happens. Nothing loads, Eclipse doesn't give me an error output, just nothing. Odd thing is that it just happens like that on one single project. When i try to import other projects, everything works just fine.
I am a 100% certain that my project is not corrupted or anything. I just removed it from the Package Explorer and now it won't work anymore.
Thank for your help :)
Once try this:
File->Import->General->Existing
Projects into Workspace, Next
Select root directory: /path/to/project
Projects->Select All
UNCHECK both "Copy projects into workspace" and "Add project to working sets"
Finish
If you just removed the Project from Project Explorer, then Eclipse specific files (.project and .classpath) must be still there. Try to import it as existing Eclipse project: Import -> Existing Projects into Workspace.
I had this problem recently. As it turns out, the AndroidManifest.xml contained a duplicated entry (syntax error), causing a parse failure when Eclipse tried to decode it.
After I found the duplicate line, removed it, and re-added the project to my workspace, it showed up in Package Explorer just fine.
Hope it helps.
For my case there was a problem in manifest . Check whether Manifest is proper or not or any other Xml file has any sort of problem .

Error in Eclipse: "The project cannot be built until build path errors are resolved"

I am a computer science student learning Java, so I do some work at home and at college on a mixture of Linux and Windows. I have a problem after copying a new project into the Eclipse workspace. The project shows up, but with a red exclamation mark and an error saying:
The project cannot be built until build path errors are resolved
How can I fix this? I tried the solution described here, but it didn't work.
Identify "project navigator" or "package explorer" view.
Right click on your project, select Build Path --> Configure build Path.
In the emerging window, you will find four tabs, select "Libraries".There, under "Web app libraries" (expand it), you will see the libraries added to the project's classpath. Check if all of them are available. If one or more are not (they'll have "missing" beside their name and a red mark on their icon), check if you need them (perhaps you don't); if you don't need them, remove it, if you need them, exit this window, look out for the missing jar and IMPORT it into your project.
Open the Problems view. You can open this view by clicking on the small + sign at the left hand bottom corner of eclipse. It's a very tiny plus with a rectangle around it. Click on it and select problems.
The problem view will show you the problems that need to be resolved.
If the message says "the project is missing the required libraries...", you need to configure your build path by right clicking on your project, selecting properties, then build path. Add the required jar files using the libraries tab.
-If there are other problems other than missing libraries, you need to post the exact problems here to get a precise solution.
If you can't find the build path error, sometimes menu Project → Clean... works like a charm.
In my case, all libraries in the build path were OK.
To solve it, I deleted all project metadata (.project, .classpath, .settings) and re-imported the project as a Maven project.
Right click your Project > Properties > Java Build Path > Libraries
Remove the file with red "X" (something like JRE...)
Add Library
That's how I solved my problem.
I also had this problem in my system, but after looking inside the project I saw the XML structure of the .classpath file in the project path was incorrect. After amending that file the problem was solved.
If not working in any case...then delete your project from the Eclipse workspace and again import as a Maven project if that is a Maven project. Else import as an existing project.
I tried all the previous given solutions, but they didn't work, but it works for me.
In Eclipse, go to Build Path, click "Add Library", select JRE System Library, click "Next", select option "Workspace default JRE(i)", and click "Finish".
This worked for me.
Go to Project > Properties > Java Compiler > Building
Look under Build Path Problems
Un-check "Abort build when build path error occurs"
It won't solve all your errors but at least it will let you run your program :)

Categories

Resources