Intellij Cannot resolve character at import

This problem periodically occurs for different libraries and different projects. If you try to import the library, the package will be recognized, but the class name cannot be resolved.

If in the import statement I right-click -> Goto -> the package declaration , I see all the decompiled classes displayed in the sidebar - including the ones I need - If I try to automatically populate the import statement, I noticed that the class in which I need is not displayed in the drop down list.

I already tried to invalidate the caches, it doesn't work. I can not find any class conflicts - in my classpath there is no other jar file with the same package name. I can import this class into other projects.

Please view screenshots:

enter image description here

enter image description here

Who has a key?

+100
java classpath import intellij-idea
Nov 15 '14 at 23:39
source share
25 answers

you can try to invalidate the cache and restart intellij, in many cases this will help.

File -> Invalid Cache / Reboot

+186
Dec 16 '14 at 16:01
source share

There may be several reasons. In my case, it was the wrong problem with the original root. Invalid caches did not work along with other solutions.

Check the source module roots.

  • Project structure (Ctrl + Alt + Shift + S).

  • Modules

  • Choose your problem module.

  • The Edit tab at the top of the Sources window.

  • Remove unnecessary source roots. Save it and add the src and test roots to this root.

+36
Oct 07 '15 at 17:54
source share

Check your module dependencies.

  • Project structure ( Ctrl + Alt + Shift + S ).
  • Modules
  • Choose your problem module.
  • Change the tab at the top of the Dependencies window.
  • Check which library is needed (maybe you need to add the specified library in the tab libraries) or the module is listed here and it has scope ('complile' right).
+11
03 Sep '15 at 9:18
source share

I encountered a similar problem, Mike's comment helped me move towards its solution.
Although the required library was also part of the module in my project, this required a change of scope. Depending on the module, I changed the area to Compile , rather than Test , and now it works great for me.

+10
Apr 30 '15 at 10:50
source share

IntelliJ has problems resolving dependencies. Try the following:

  1. Right click pom.xml -> Maven -> Reimport
  2. .Right-click pom.xml -> Maven -> Create Source Code and Update Folders
+9
Feb 02 '18 at 19:24
source share

File -> Invalidate Caches / Restart or rebuilding the project did not work with me.

For my Gradle project, the “Update all Gradle projects” worked on the “Gradle” tab in the upper right corner of IntelliJ v2017, using the yellow checked button shown below:

enter image description here

+7
Jun 25 '18 at 13:20
source share

I found the following answer @ jossef-harush and @ matt-leidholm useful from another link

  • in the IntelliJ editor, press the red keyword (e.g. Integer ) and press ALT + ENTER (or click the light bulb icon)
  • select Setup JDK from the intent menu

IntelliJ intentions menu

  • click Configure

Project SDK selection dialog

  • In my case, the JDK path was wrong (pointed to /opt/jdk1.7.0_51 instead of /opt/jdk1.7.0_65 )

Broken Configure SDK dialog

  • click on ... and go right JDK path

Fixed Configure SDK dialog

  • free cache

IntelliJ File menu

+3
Oct 28 '17 at 17:40
source share

File → Invalidate Caches / Restart And also Create your own project

+3
Feb 13 '18 at 4:14
source share

Right-click on the pom.xml file, go to Maven, click Reimport. I had a similar problem and it worked for me.

+3
Sep 18 '18 at 5:35
source share

I tried invalidating the caches and rebooting, but the only thing that worked for me was to completely destroy the .idea directory and then create a new project from scratch.

+1
Aug 10 '16 at 0:07
source share

I also got this error several times when I try to create a new java project.

Below is the step how I got this stupid problem.

  • Create an empty project and create a new src/main/java directory.
  • Create the source package net.gongmingqm10.sketch .
  • Use gradle wrapper , gradle idea to create gradle material for a project.
  • Add some dependencies to the build.gradle file and gradle build , reimport project.
  • Create User.java and School.java in the existing net.gongmingqm10.sketch package
  • I got an error while I try to use Import School in User.java.
  • Intellij continues to complain, cannot allow import of the character.

Decision:

First create a project 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 problematic packages to the new package.

The root cause:

Source Tree Directory Tree

As you can see from the tree. I got a directory named net.gongmingqm10.sketch . But we really need a directory with three levels: net-> gongmingqm10-> sketch

But before completing the project in Intellij, I create a new directory called net.gongmingqm19.sketch , which will give me a real directory named net.gongmingqm10.sketch .

When we try to import it. Obviously, how can I import a file under an element directory called abc .

+1
Aug 19 '16 at 17:59
source share

@ Anton Dozortsev I was confused by such behavior; I ended up reinstalling the IDE a bunch of times, only missing the problem after uninstalling the IDEA application, all caches, settings, etc.

I tried all kinds of steps in the interim (e.g. restarting, invalidating, deleting .idea and *.iml , etc.)

It turns out the problem is with the IntelliJ idea.max.intellisense.filesize . I set it to 100 KB, which was less than the size of my dependency, which led to IntelliJ showing it as unknown, as in the screenshot.

Fix:

  • Click Help → Edit Custom Properties

  • Set the property to a larger value; default is 2500 KB idea.max.intellisense.filesize=2500

+1
Jun 12 '17 at 17:09 on
source share

I had the same problem until I noticed that the src folder was marked as root instead of java ! Switching to java (src / main / java) as the source root solved my problem enter image description here

+1
Jul 11 '18 at
source share

Run this command in the project console:

 mvn idea:idea 

Done. There has been this question many times. Tried 'Invalidate Cache & Restart all other solutions. Running this command works great for me. I am currently using IntelliJ 2019.2, but this also happened in previous versions, and the solution worked as well.

+1
Sep 11 '19 at 16:12
source share

A simple restart worked for me.

I would suggest trying with a reboot first, and then you can choose the cache invalidation.

PS: Clearing system caches will clear local history.

0
Dec 09 '16 at 23:02
source share

I had a similar problem with my imported Maven project. In one module, it cannot allow importing a symbol for part of another module (yes, part of this module can be allowed).

I changed the "Maven home directory" to a newer version, solving my problem.

Update: good for 1 hour, return to broken status ...

0
Jan 11 '17 at 22:16
source share

I found the reason for the source!

In my case, I add a jar file that includes some java source file, but I think the java source is bad, in the Intellij Idea dependency library it adds the source automatically, so the editor imports BAD, just delete the source code in the "Project Structure" → "Library", it works for me.

0
Apr 23 '17 at 0:02
source share

What I need is to edit the package file in the .idea folder, since I accidentally added sources to this jar library, and android could not fix it by deleting the source line marked in the b / m image library error .

Then rebuild the gradle and bam problem.

0
May 01 '17 at 17:06
source share

I had the same problem and the reason for this was the mis-labeling of the project sources.

I manually created the root content and did not notice that the src/main/test folder was marked as Sources instead of Tests . Therefore, we suggested that my test classes have all their test libraries ( JUnit , Mockito , etc.) with the compilation volume, and not with the test.

As soon as I designated src/main/test as "Tests" and rebuilt the module, all errors disappeared.

0
Jun 05 '17 at 12:40
source share

I had this recently, when I tried to use Intellij to work on NiFi, it turned out that the problem is that NiFi requires Maven> = 3.1.0, and the version I checked with (I think by default) was 3.0. 5. Updating the Maven version for the project fixed this, so in some cases the Maven version might not be aligned correctly ... I think this is rather unusual, but if you go this far in the stream, you will probably get an unusual problem :)

0
Jan 03 '18 at 18:54
source share

Same problem. If these methods do not work. You can try to remove the library from the local maven repository and import it again into pom.

mvn repository

Finally, this is good for me.

project

0
May 13 '18 at 9:44
source share

fileProject StructureModules , find the module with problems, click it and select the Dependencies tab on the right side. Click the green plus sign, try adding the jar or libraries that are causing the problem. This is suitable for me.

0
Oct 25 '18 at 11:58
source share

After a long search, I found that the dependency was somehow damaged on my machine in the maven project. The strange thing was that in the compiled Java code, the dependency still worked correctly. However, when I cleared and rebuilt the maven dependency cache, the problem disappeared and IntelliJ recognized the package. You can do this by running:

 mvn dependency:purge-local-repository 

Interestingly, the source of my problem, therefore, was not IntelliJ, but Maven itself.

0
Feb 14 '19 at 13:46
source share

Please try File-> Sync. Then close and reopen IntelliJ before invalidating.

Once I restarted. I would invalidate, but synchronization cleared everything after restart.

0
Jul 30 '19 at 15:28
source share

Missing io ? Try import org.openide.util.io.ImageUtilities .

-one
Apr 11 '17 at 16:58 on
source share



All Articles