Related
This problem happens intermittently for different libraries and different projects.
When trying to import a library, the package will be recognized, but the class name can't be resolved.
If on the import statement, I right-click -> Goto -> the package's declaration, I see all the decompiled classes displayed in the side pane -- Including the ones I need --
If I try to auto-complete the import statement, I notice the class I need is not featured in the dropdown.
I tried invalidating caches already, doesn't work. I cannot find any class conflicts -- there is no other jar file in my classpath with the same package name.
I am able to import this class into other projects.
Please see screen shots:
Anyone have a clue?
You can try invalidating the cache and restarting IntelliJ, in many cases it will help.
File -> Invalidate Caches/Restart
There can be multiple reasons for this. In my case it was wrong source root issue. Invalidate caches didn't work along with other solutions.
Check your module source roots.
Project Structure (Ctrl+Alt+Shift+S).
Modules
Select your problem module.
Change tab on top of window "Sources".
Remove unwanted source roots. Keep one and add src and test source roots in this root.
File -> Invalidate Caches/Restart
And
Build your project
IntelliJ has issues in resolving the dependencies.
Try the following:
Right click on pom.xml -> Maven -> Reimport
Again Right click on pom.xml -> Maven -> Generate sources and update folders
Run this command in your project console:
mvn idea:idea
Done.
Had this issue many times. Tried 'Invalidate Cache & Restart' and all other solutions. Running that command works perfect to me.
I'm currently using IntelliJ 2019.2, but this also happened in previous versions and solution worked as well.
File -> Invalidate Caches/Restart or rebuilding the project did not work wor me.
What worked for my Gradle project was to "Refresh all Gradle projects" from the Gradle tab on top-right corner of IntelliJ v2017, using the yellow marked button shown below:
Check your module dependencies.
Project Structure (Ctrl+Alt+Shift+S).
Modules
Select your problem module.
Change tab on top of window "Dependencies".
Check what needed library (maybe, you need to add specified library
in the tab 'libraries') or module has listed here and it has right
scope ('complile' mostly).
I faced a similar issue, Mike's comment helped me move in the direction to solve it.
Though the required library was a part of the module in my project too, it needed a change of scope. In the module dependency, I changed the scope to "Compile" rather than "Test" and it works fine for me now.
Had the same problem till I noticed that the src folder was marked as root source instead of java!
Changing to only the java (src/main/java) to be the source root solved my problem
I found the following answer from #jossef-harush and #matt-leidholm useful from another link
in IntelliJ editor, click on the red keyword (Integer for example) and press ALT + ENTER (or click the light bulb icon)
select Setup JDK from the intentions menu
click on Configure
In my case, the JDK path was incorrect (pointed on /opt/jdk1.7.0_51 instead of /opt/jdk1.7.0_65)
click on the ... and browse to the right JDK path
let's clear the cache
Right click on pom.xml file, go to Maven click on Reimport. I had similar problem and this worked for me.
After a long search, I discovered that a dependency was somehow corrupted on my machine in a maven project. The strange thing was that the dependency was still working correctly in the compiled java code. When I cleaned and rebuilt my maven dependency cache however, the problem went away and IntelliJ recognized the package. You can do this by running:
mvn dependency:purge-local-repository
Intrestingly, the source of my problem hence wasn't IntelliJ, but maven itself.
For 2020.1.4 Ultimate edition, I had to do the following
View -> Maven -> Generate Sources and Update Folders For all Projects
The issue for me was the libraries were not getting populated with
mvn -U clean install from the terminal.
Try cleaning maven from upstream by:
mvn -U clean install
I also got this error for multiple times when I try to build a new java project.
Below is the step how I got this stupid issue.
Create an empty project, and create new directory src/main/java.
Create the source package net.gongmingqm10.sketch.
Use gradle wrapper, gradle idea to build the gradle stuff for the project.
Add some dependencies in build.gradle file, and gradle build, reimport the project.
Create User.java and School.java in the existing package net.gongmingqm10.sketch
I got the error while I try to use import School in User.java.
Intellij keeps complain can not resolve symbol on import.
Solution:
Build the project first, and mark the main/java as the source root. Create a new directory with the same name net.gongmingqm10.sketch. Move all the files from the old troubling packages to new package.
Root cause:
Directory tree of source code
As you can see from the tree. I got a directory named net.gongmingqm10.sketch. But what we really need is the 3 levels directory: net->gongmingqm10->sketch
But before I finish building my project in Intellij, I create new directory named net.gongmingqm19.sketch, which will give me a real directory with the name net.gongmingqm10.sketch.
When we trying to import it. Obviously, how can intellij import the file under the weired directory with the name a.b.c.
#Anton Dozortsev I was driven crazy by a similar behavior; I ended up re-installing the IDE a bunch of times, only getting past the issue after removing the IDEA app, all caches, preferences, etc.
I tried all kinds of steps in the interim, (like restarts, invalidations, deleting .idea and *.iml files, and others.)
Turns out, the problem was due to IntelliJ's idea.max.intellisense.filesize setting. I had set it to 100KB, which was smaller than my dependency's size, leading to IntelliJ showing it as unknown, just like in your screenshot.
Fix:
Click on Help -> Edit Custom Properties
Set the property to a larger value; the default is 2500KB
idea.max.intellisense.filesize=2500
Please try File-> Synchronize. Then close and reopen IntelliJ before you invalidate.
Once I restarted. I would have invalidated but the synchronize cleared everything after restarting.
Simple Restart worked for me.
I would suggest first try with restart and then you may opt for invalidating the cache.
PS : Cleaning out the system caches will result in clearing the local history.
I found the source cause!
In my case, I add a jar file include some java source file, but I think the java source is bad, in Intellij Idea dependency library it add the source automatic, so in Editor the import is BAD, JUST remove the source code in "Project Structure" -> "Library", it works for me.
What did it for me is to edit the package file in the .idea folder as I accidentally added sources to this jar library and android couldn't resolve it by deleting the sources line as marked in the b/m picture library error.
Then rebuild the gradle and bam problem solved.
I had the same issue and the reason for that was incorrect marking of the project's sources.
I manually created the Root Content and didn't notice that src/main/test folder was marked as Sources instead of Tests. So that is why my test classes were assumed to have all their test libraries (JUnit, Mockito, etc.) with the scope of Compile, not Test.
As soon as I marked src/main/test as Tests and rebuilt the module all errors were gone.
I had this recently while trying to use Intellij to work on NiFi, turned out the issue was that NiFi requires Maven >= 3.1.0 and the version that I'd checked out with (I guess my default) was 3.0.5. Updating the Maven version for the project fixed it, so in some cases Maven version mis-alignment can be a thing to look...I'd guess it's fairly unusual but if you get this far on the thread you're probably having an unusual issue :)
file-> Project Structure -> Modules, find the module with problems, click it and choose the Dependencies tab in the right side. Click the green plus sign, try to add the jar or libraries that cause the problem. That works for me.
Nothing I tried above worked for me (not that I tried every suggestion). What finally did the trick was to rename the class -- I just added a 2 to the class name and filename. Then I resolved all the references manually. (Since they weren't recognized, the refactoring did not change the references automatically.)
Once the "2-version" was happily resolved everywhere, I was then able to refactor and remove the 2 from the class and file, and everything was then as it should be.
in my case the solution was to add the project as maven project, besides the fact that i imported as maven project :P
go to pom.xml -> right click -> add as maven project
My issue was my Maven plugin got disabled after an update. I went to Help -> Find Action... -> Typed in Maven and found that it was "Off". I clicked the toggle switch and after a bit of loading it was re-enabled.
Also, check your class is not in compile exclusions
If you see, that there is a little grey cross in left top corner, you must remove class from compile exclusions
How to remove
Old question, '21 response. I ran into the issue where my go build would build code successfully but my Goland IDE showed missing modules or dependencies. I tried Invalidating Caches and Restart, but had the same problem. From another S/O thread, I tried adding the GO111MODULE=on to my Path Variables, but that didn't resolve the IDE problems either.
What worked for me was picking the correct GOROOT path in Preferences > Go > GOROOT.
I had two versions of go installed, one by brew and one from the online Go installer. I selected the brew install path, and my IDE was able to resolve the dependencies properly.
I've tried all the complicated methods and they didn't work, since I was too lazy to re-import the project I tried something else.
Mine is a gradle project, so I went to my gradle.build file, removed the dependency, refreshed the dependencies, then added the dependency again and refreshed again, the imports started working after that.
Faced similar issue,
I Updated Intellij and error start coming - Can't Resolve Symbols.
Went to Plugins, Updated the plugins & Restart
Problem Solved !!
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.
Got a new pc, and trying to import an existing maven project into IDEA (version 2018.3), with following steps:
import -> import project from external model -> maven
But, after importing, there is no src dir, I have tried many times, each time delete .idea/ before re-import.
I remember it did work before, but not this time.
And, I can compile the project successfully with mvn compile, also Eclipse could import it correctly.
Any idea what's wrong, and how to fix it?
First check if your intelliJ is collecting POM dependencies, on large projects it can go for hours. During collecting dependencies you will see no folders, but only root files.
If the above is not the case, right click on white project area/Maven/Reimport.
If you don't see it or that doesn't fix the problem, go to File->Project Structure... then choose Modules and check if you have duplicated modules and remove them.
I've addressed this problem by myself.
I've set up my IDEA using my previous setting backup, which therefore lead to the result that there are some legacy settings regarding maven and were imported by IDE.
A reasonable inference is that this is a built-in bug.
Restore the IDEA to default settings help address this problem.
Happy coding 🤣
Since last night, Eclipse hasn't been letting me run any of my projects and gives me the error "Your project contains error(s), please fix it before running it".
This happens regardless of which project I use.
There are no code errors in any projects
There are no missing files (R.java, etc.) or folders (src, res, etc.)
There are no errors in the console (even on verbose) or the error log screen
I've cleaned all the projects, and each individual project many times
I've restarted ADB, Eclipse, and my computer
I have no idea what to do next, so hopefully its fixable.
NOTE: I am using Git, and this occurred after switching to my master branch to export a new update to one of my apps.
Thank you in advance! (:
Edit 1: I have also tried deleting and re-importing the projects before I posted this.
Click Window -> Show View -> Problems, that should show what exactly Eclipse thinks is wrong with your project. Sometimes you can simply delete the problem from that view, and Eclipse believes you everything is fine (yep, weird, I know).
Also, after you switch branches using an external source control tool (one not integrated into Eclipse through a plugin), Eclipse sometimes won't pick up all changes, you'd need to manually refresh the whole project file tree.
If nothing else helps, try setting up a new Eclipse workspace and importing your project there.
check your build paths - there could be jars and dependencies that are outside of the app that need to be opened or imported.
another trick is to edit an xml file, just change one word to intentionally cause an error, save the file, then change it back to proper syntax and save again. Error magically disappears.
another trick is to edit a java file, (cause error, save, fix error, magically error free)
I had this problem and I have fixed it. My issue was this:
I somehow managed to require another project in my build. That project had errors in it, which I believe is what caused the issue. I think this happened when I accidentally asked Eclipse to fix my build path or something when I was trying to fix a mistake. To correct this issue go to (on mac):
Right click on your project folder in the Package Explorer
In the menu, go to "Build Path"
Select "Configure Build Path"
Go to the "Projects" tab (along the top).
Is there anything in there? If there is and you weren't expecting there to be, select the project that is in that folder and hit "Remove"
This fixed the issue for me. Hope it helps.
I think you need to clean your project. Do project -> clean. Should work fine after that.
Try using Project->Android Tools->Fix Project Properties besides checking for your Android path. Check if your ANDROID_HOME and ANDROID_SDK are set correctly besides adding tools and platform-tools are set correctly in environment variable PATH.
Hope this helps!
Go to your .android folder and delete your debug certificate.
E:\Users\(your profile)\.android
Inside that folder there is a file name 'debug.keystore'. Delete that, clean and try to build the project again. Sometimes this error is caused when the certificate expires.
I found this answer here and it solved my problem ;-)
I think go to project ->clean some error can be solve this problem
Go to Projects in the menu bar
Then check the menu Build Automatically.
This helped for me.
I'm using Eclipse for Java development. All my sources compile fine and the resulting application compiles fine. However, I keep getting an "red-x" error notification in the Package Explorer.
All my sources in this source directory (too long for the snapshot) compile fine, none of the show the "red-x" error icon.
Any suggestions on how to fix the problem would be highly appreciated.
yeah, this happens sometimes for no apparent reason. You can go to the "Problems"-Tab (right next to console output) and see the error message, so maybe you can narrow it down that way.
This happens often when I use Maven, and I had always ignored it until I found this question. You need to update the project in this case (figured this out by looking in the Problems pane)
From the project context menu: Maven -> Update Project and select the available maven codebases
Alternatively you can use (Alt + F5) to bring up the same window
Try to clean the project and rebuild it.
After build. Refresh project and if still persist just right click Problems tab in eclipse and choose delete all.
It often happens if you do maven install and eclipse properties files do not get updated properly. Even though your project does not have any errors. Hopefully!
I want to start by thanking everyone that answered. But cleaning and rebuilding was not enough in my case because the problem was still there and needed fixing.
Turned out that one of my package directories had accidentally been copied so that an extra directory now existed called "Copy of dagskra" containing Java files with wrong package declarations. In addition the errors in this "new" directory don't show up with a "red-x" in the package that it exists in:
Snapshot from Package Explorer showing errorous "Copy of dagskra" directoryr http://www.freeimagehosting.net/uploads/a824304b18.png
It was the hint of reading the "Problems" tab :-) that turned me into the right direction, so I'm selecting that answer as the accepted answer because this is what I needed:
Snapshot from Problems tab http://www.freeimagehosting.net/uploads/dea26d5dd0.png
Hoping this will help others...
So upon finding that there could be a missing package in the buildpath, thus the red x against the main project, to remove this:
1) go into "Configure Buildpath" of project
2) Java Build Path -> Source Tab - you should see the red x against the missing package/file. if it no longer exists, just "remove" it.
red X begone! :)
Sometimes there are build path errors in .project, and you need to switch to Resource view to actually see the file that is causing the error.
As others have said, bad file references in the build path is often the culprit.
Usually a .jar file that has been moved/deleted. Eclipse expects to find everything referenced on the build path at the location specified, and will complain if not.
I had the same issue and below steps resolved the issue:
Delete the JRE from PROJECT> properties>java build path> libraries.
Restart the eclipse
Add the JRE again
Rebuild the project using Project>Clean and chose option to build automatically.
Please try.
Subversion is occasionally the culprit for this as well. It might not have anything to do with your environment. But, there might be a discrepancy between the current and local state of the project. In my case, doing an update, and then a commit to the subversion server provided me with the expected clean result without any flags in the project such as the X.
In my case what solved this problem was simply to Close Eclipse and opening it again...However I am still not sure why this happened or why it worked. I was having problems Cleaning my project (it said it could not Delete certain file) and this solved it :):
Try doing a rebuild. I've found that the red x's don't always disappear until a rebuild is done.
I've run into a similar problem many a time, what happens usually for me is that a java file will say it won't compile in the text editor but in the package explorer it will say it's compiling fine.
Sometimes doing a 'rebuild' or 'clean-build' doesn't work, the files don't actually get built (one has to presume that eclipse thinks the files it has are up to date) and when this happens I usually open up the java build path and just move one of my dependencies down/up the pecking order. This forces eclipse to do a rebuild of everything and it always seems to work.
If you're still having problems try copying the project and seeing if you get the same behaviour and at a last ditch attempt post a bug for eclipse, it may take a while for them to fix but at least you know that you're being heard.
To add to the previous answer, an extreme way of "cleaning" your project is to delete it (that is deleting its reference from the workspace, not deleting the actual files), and then re-import it.
Sometimes, it helps...
FindBugs also puts a red-x against files/packages to indicate static code analysis errors.
I have run through this. My case was more involved. The project was packaged fine from maven command line.
Couple of things I made.
1. One class has many imports that confused eclipse. Cleaning them fixed part of the problem
2. One case was about a Setter, pressing F3 navigating to that Setter although eclipse complained it is not there. So I simply retyped it and it worked fine (even for all other Setters)
I am still struggling with
Implicit super constructor Item() is undefined for default constructor. Must define an explicit constructor"
I also experience those misterious error-symbols on packages from time to time. A way to get rid of them that works for me is to effectively remove the JRE System Library from Java Build Path and add it back again.
My solution that finally worked was to clean all projects, close eclipse, clean all projects, close eclipse, and so on at least 5-6 times. Eventually it all settled down and everything was as expected. Weirdest thing ever!!
And no there were no errors in the Problem or console view.
Also this happened after a computer crash. The last time it happened my whole workspace was completely lost. It was still there on the computer, but when I tried to access it, it would be all blank.
For whatever reason computer crashes are really really really badly handled by eclipse.
Also, you may update the project by clicking,
Right Click on project name -> Select Maven -> Right click -> Update Project.
This helped out for me.
Thanks.
This can occur for a number of reasons. If you have changed the jdk, the Project facet will have a red X next to it while no other folders shows an error. If this is the case, modify the jdk that is shown. This happens on occasion in our JAX-WS class (HSG
I solved mine by
Close all other projects (i.e. unrelated project option)
Clean and build
My project was android, and that did it.
This happened when i downloaded fabric.io on Eclipse Mars but Restarting computer solved this problem for me.
i had same problem. I checked "Problems"-Tab and found no server for the project. I defined the server. the red-x disappered
You can go to project-> Buildpath-> Library
If there is any library that is X marked ie [cross marked] removed it and again try to build. It worked for me as well/
I encountered this problem today and found this link. I followed as mentioned by Patrick Schaefer above and opened the Update Maven project Dialog. Click on my working project and selected the checkbox "Force Update of Snapshots/Releases" and 'Ok'. All the red cross vanished.
I hope this helps anybody in a similar situation.
The question is old but I had this issue and I tried the following to no avail.
mvn update (with snapshots)
remove project and re-importing
clean build
restarting Eclipse
changing order of items in build path
In my case I've got multi module mvn projects and one of the nested projects was showing a red X icon only in the Project Explorer (package explorer and problems were totally fine) and the whole project was fine as I could run classes without any issues. So seemed like a display issue.
The only thing that worked for me was to edit the pom.xml if the offending project module and make a breaking change (add 'xxx' to a tag name) which caused 1000s of errors and then undo.
You may clean the project by clicking,
In Eclipse, Right Click on Project -> clean
This helped out for me and saved a lot of time.
Thanks.
Right click on the project with errors, then in the sub-menus select:
Maven > UpdateProject >
and then:
Select the checkbox for all the dependent projects
select force update of snapshots
click OK.
This worked for me..