Intellij IDEA cannot resolve any import statement

Answered

Hi there,

 

I am struggling recently with very strange issue. Suddenly, my intellij IDEA stopped resolving all java import statements.

 

The only solution that worked so far for me was to uninstall intellij IDEA and install it again. Although, when I import one of my projects upon ~4 hours it cannot resolve any import statement again. This happes only for that one project. It is Eclipse RCP based.

 

Unfortunatelly, I cannot share with you the source codes of that project.

 

What I have already tried is the following:

  1. Remove .idea folder
  2. Remove all *.iml files
  3. Invalidate and restart

None of this works for me. When I create project from the scratch it also tells me that import statements cannot be resolved

 

My intellij IDEA version: 2019.1 Ultimate

 

 

It cannot event resolve base classes like String

 

My SDK is set up properly

 

Thank you for your help.

 

Maks

1
59 comments

Hello Jjurco Sk,

The issue is not yet reproduced on my side. Can you please check if your JDK 14 version has "java.sql" (you may check it in Project Structure | JDKs)? Thank you 

0

Yes, I do have it. I'm also able to run the project through Idea. 

In the afternoon I'm going for holidays so I may not be responsive for some more than week. 

0

Hello Jjurco Sk

Can you please share the idea.log file (Help | Show Log in Finder, may be uploaded here: http://uploads.services.jetbrains.com/) and take the screenshot of how the "unfound" library looks like it the Project Structure view. Does java.sql have folders, classes there? Thank you 

0

Please also try to enable the following option "idea.invalidate.caches.invalidates.vfs" in the Registry before the invalidate/restart and check if it helps:

Thank you and sorry for inconvenience.

0

I'm having same problem as most with 2020.2 release.  I have to "invalidate cache" periodically for my "import static" to resolve.  Is there a fix?  I have monitored this thread and I do not see any indication that this is a bug.  Does anyone have any idea on how to fix this issue

0

Delete the System directory: https://www.jetbrains.com/help/idea/tuning-the-ide.html#system-directory when the IDE is not runing and see if it helps.

If the issue persists, file a bug at https://youtrack.jetbrains.com/newIssue?project=IDEA with the screenshot of the issue and the logs attached (Help | Collect Logs and Diagnostic Data).

0

Thank you. I have done as you’ve requested. If the problem persists with this release, I will open an issue with screenshots and logs.

0

In my case File -> Invalidate Caches/Restart... alone helped without deleting .idea folder and *.iml file  jazz.

2

Just to add my 5 cents to the discussion. None of the suggestions seemed to fix my issue. I've tried reinstalling the IDE, changing the version and nothing helped. In the end, I found out that somehow my JDK got uninstalled from my PC (it was separately installed, not as part of IntelliJ), which was the cause for the IDE not locating classes from the Java core libraries. I'd suggest in addition to the other solutions, to make sure there is a valid JDK on the machine and the IDE is pointing to it.

 

1

Please try to delete  C:\Users\<user_name>\AppData\Local\JetBrains\IntelliJIdea2020.X\  folders all together if you are in Windows.

No worries those necessary will be recreated.

 

0

I had a similar issue , I resolved it by changing the java version that intellij uses to java 11. This will happen if we have mentioned different java version at different places in intellij. 
Make sure the java version is same in all the places 
1. File -> Project Structure -> Project -> Java 11 (Example)

2. File -> Project Structure -> Modules -> individual project module -> Java 11 (Example)

3. File -> Project Structure -> SDK's -> Java 11 (Example)

4. Intellij -> Preferences -> Compiler -> Java Compiler -> Java 11 (Example)

This is in Mac intellij, making sure i use same Java version in all the above locations resolved this issue for me. Hope this helps .

0

Hello, please try the latest IntelliJ IDEA version, the issue with unresolved imports from JDK must be resolved there: https://www.jetbrains.com/idea/nextversion

0

Do we have solution for that? I got that problem after upgrading to 2021.1 :( so far nothing helps...

0

Hello, 

Please file an issue to our YouTrack: https://youtrack.jetbrains.com/issues/IDEA and attach the log files to it, we'll investigate the problem. Thank you 

0

I have same issue with IntelliJIdea2021.1 Ultimate. (windows) not recognizing some imports and say 'Cannot resolve symbol xxx' and shows red.  

SpringBoot project Maven project. It compiles with 'mvn clean install' from command line and Intellij Maven build.

The all errors seem to be in annotation package.

Project Setting using : ProjectSDK=11,  Available SDKs: C:\pkgs\JDK\openjdk11.0.8.10 (11) and C:\Program Files\Java\jdk1.8.0_74 (1.8)  available.

File | Settings | Build, Execution, Deployment | Compiler | Annotation Processors  for the project (not default) set to "Enable Annotation Processing" , "Module content root" with "Production sources directory" : "target\generated-sources\annotations" , "Test sources directory": "target\generated-test-sources\test-annotations"

Some of the things I have tried.

I removed .idea directory and *.iml files from project.

removed C:\Users\<userID>\AppData\Roaming\JetBrains\IntelliJIdea2021.1

Deleted the C:\Users\<userID>\.m2\repository and rebuild the project on command line.

"Invalidate and Restart"

Restricted environment at work so I'll have to see what I can upload.  Please suggest any other ideas :) (pun intended)

0

Is it possible to share idea.log ("Help | Show Log in...") after restarting ID and running "Reload" from Maven Tool Window?

0

My problem is that I update the IDEA and all imports are not working.

Thank god. File -> Invalidated Cache and Restart save me.

 

0

Wanted to put in my fix in case it helps anyone. I deleted my target file and ran a clean build. All imports are working as expected. This was after update 2021.1

0

Hey,

I'm just a newbie, but I had basically the same Porblem on my Android Project for my University course. To resolve this issue i just had to select (and apply) a different Project SDK in the Project Settings and then I had to switch back to the old one and the issue was gone.

Hope this will help someone.

0

I was also facing the same issue I tried almost all the suggested ways from different platform. Finally File -> Invalidate Caches/Restart worked for me... and issue got resolved.

0

Had similar problem after upgrading Intellij. Was the SDK that had gone missing, because I used the embedded JDK.

0

I face the issue sometimes, when i created a new project witrh an preselected sdk.

it helped to just change the sdk to something and than back to the one i want to use.

 

0

For whatever it's worth, on my Maven project I had to:

Right-click pom.xml -> Add as Maven project

I hope this helps someone!

0

After struggling for literally 1 week, I finally found the solution. I tried so many permutations & combinations suggested in so many threads, but nothing actually worked for me.

Here's the thing:

IntelliJ is showing the errors because the dependencies are internally messed up. It doesn't mean they don't exist! They do, but mixed up. If there is an internal conflict with the wrong existing dependency, IntelliJ blindly skips it - which causes these huge errors for us.

Best course of action, according to me is: Delete all the contents inside .m2 repository & re-run maven clean install from terminal. Then re-load projects in IntelliJ

0

Its unfortunate that it still happens in 2022.

1

Shekhar Sahu

Different things can cause this, that's why there is no intuitive solution or universal preventive measure for it yet. We are working on improving the situation.

0

After about 7 hours messing around with this issue, (only some imports were not resolving, and they were there right there in the project directory structure and no reason resolving imports should have been an issue)

File -->  Repair IDE

finally did the trick for me.

0

So this one was a nightmare, but I found something that worked for me.  After I made sure my local java version/location was pointing to the correct JDK (which was important), I tried restarting, rebuilding, reconfiguring, deleting and reinstalling, and basically everything in this thread.  Decided to remove the Maven m2 folder, and low and behold the project started reinstalling all dependencies automatically because they didn't exist anymore.

rm -rf ~/.m2/

I almost cried I was so happy.

0

Please sign in to leave a comment.