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\'
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.
@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
IntelliJ has issues in resolving the dependencies. Try the following:
Check your module dependencies.
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.
src/main/java
.net.gongmingqm10.sketch
.gradle wrapper
, gradle idea
to build the gradle stuff for the project.build.gradle
file, and gradle build
, reimport the project.User.java
and School.java
in the existing package net.gongmingqm10.sketch
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
.
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.