Reputation: 2724
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?
Upvotes: 245
Views: 518227
Reputation: 1689
I have had this issue multiple times, specially when importing a new project. In my case, there are projects based on spring-boot that includes multiples dependencies that causes Intellij to go mad the first time you import it.
As other answers here are valid, to know which one will suit better in your case, first check the log on Intellij:
~/.cache/JetBrains/IntelliJIdea202X.X/log
Where the folder must match your current Intellij version. Here in some cases I have noticed some issues with some plugins that are causing some exceptions (in my case Checkstyle
). Disabling the plugin, and invalidating the cache and restarting has solved the issue.
In other cases, I notice the classical:
Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
On the logs, but it is not reflected on the Intellij UI.
Where increasing the heap memory of the project on Intellij settings Build, Execution, Deployment -> Compiler -> Shared build process heap size
can solve it as commented in others answers
Last case, I have a:
SEVERE - #o.j.i.maven - java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
That is more related to when Maven refresh the dependencies. If is the case, Change on Build, Execution, Deployment -> Build Tools -> Maven -> Importing -> VM options for importer:
and set it to -Xmx2g
or any other value.
Other example is Build, Execution, Deployment -> Build Tools -> Maven -> Runner -> VM options:
and set it to -Xmx4g
or any other value.
In any case, remember to check the log or you can spent several hours by trial and error with all the answers posted here. I have put some memory settings that must be adapted to your machine specifications. Do not copy and paste it blindly.
Upvotes: 1
Reputation: 2227
In my case, simply, I had not placed my code under path src\main\java. I had had it simply under src. When I created the src\main\java path and moved my code under that, the problem went away.
Upvotes: 0
Reputation: 412
I don't know what causes the issue. I tried everything suggested here: deleting build directory, .iml file, invalidating cache and restarting but nothing worked. IntelliJ was suggesting to update the JDK corretto-17 to Amazon Corretto-17.0.9 which fixed it.
Upvotes: 0
Reputation: 8242
I tried every answer here , What fixed my issue was deleting .idea folder , I did invalidate caches and restart before that and a simple restart after deleting .idea , The IDE asked to reimport gradle project , after the import everything started working normally.
Upvotes: 6
Reputation: 70
Faced similar issue, I Updated Intellij and error start coming - Can't Resolve Symbols.
Went to Plugins, Updated the plugins & Restart Problem Solved !!
Upvotes: 1
Reputation: 665
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.
Upvotes: 0
Reputation: 5538
You can try invalidating the cache and restarting IntelliJ, in many cases it will help.
File -> Invalidate Caches/Restart
Upvotes: 524
Reputation: 419
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.
Upvotes: 0
Reputation: 325
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
Upvotes: 0
Reputation: 728
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.
Upvotes: 0
Reputation: 149
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.
Upvotes: 2
Reputation: 776
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.
Upvotes: 62
Reputation: 1
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
Upvotes: 0
Reputation: 990
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.
Upvotes: 1
Reputation: 365
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.
Upvotes: 31
Reputation: 68
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.
Upvotes: 1
Reputation: 2015
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.
Upvotes: 3
Reputation: 92
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.
Upvotes: 0
Reputation: 103
Right click on pom.xml file, go to Maven click on Reimport. I had similar problem and this worked for me.
Upvotes: 2
Reputation: 5073
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
Upvotes: 7
Reputation: 3813
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:
Upvotes: 19
Reputation: 409
IntelliJ has issues in resolving the dependencies. Try the following:
Upvotes: 40
Reputation: 1525
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 :)
Upvotes: 0
Reputation: 450
I found the following answer from @jossef-harush and @matt-leidholm useful from another link
Integer
for example) and press ALT + ENTER (or click the light bulb icon)Setup JDK
from the intentions menuConfigure
JDK
path was incorrect (pointed on /opt/jdk1.7.0_51
instead of /opt/jdk1.7.0_65
)JDK
path Upvotes: 5
Reputation: 106
@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
Upvotes: 2
Reputation: 11
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.
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 151
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.
Upvotes: 1