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 !!
I'm fairly new to Intellij and Java and am unable to use libraries from one "module" in another. I am seeing red class names and getting "Cannot resolve symbol ..." errors all over the place:
The other modules are referenced in File | Project Structure all the other module's Paths are correct and include the *.classes I'm trying to use:
I have also tried a File | Invalidate Caches but am still having the same problems.
What do I need to do to fix this?
Listed below are steps which may fix the problem:
1.Invalidate and refresh the IntelliJ's caches
File Menu -> Invalidate Caches / Restart -> Invalidate and restart
2.Project SDK selection
Check project settings from File Menu -> Project Structure
Ensure an SDK is selected for the Project SDK. If is selected, click the 'New' button, select JDK and then select the correct path to the JDK e.g. /opt/java/jdk1.8 or c:\Java\Jdk1.8
3.Corrupt JDK
There may be a problem with your JDK installation, re-install JDK
4.Re-import the project
Close the project if it is open in IntelliJ
Delete the .idea folder in the project source code folder.
Start IntelliJ and Import the project.
You can choose any of them which will work for you.
I faced a similar problem for no reason, I think it was caused by IDE(android studio). I have tried all of the above solutions but not worked. Finally, in my own situation, I solved this problem by the following actions:
Delete your .idea folder in your local project.
Reopen this project and just let Gradle run itself.
It was worked for me. I hope that my experience will be useful for you.
You need to add your external libraries/classes under dependencies in order for IDEA to see them when doing code analysis/autocomplete.
You can go to "File->Project Structure"
From "Project Settings", Select "Project" tab and there make sure that "Project SDK" has proper JDK selection.
After you add dependencies to POM file, make it a habit to refresh POM by clicking on the 'Reimports maven projects' icon. Its the first icon in the maven tool window located to the right of the main intellij editor. Its a blue icon with 2 circular arrows. Clicking it ensures that the added dependencies are fully integrated into your project
Run it from the project's root folder.
$ mvn -U idea:idea
One more advise would be to make sure that you import the project properly. If it's a maven project, import pom.xml and if it's a gradle project, import gradle.build file to make sure that all the dependencies are downloaded correctly.
Just got this.
Just went there.
Invalidated the cache.
Seemed to work until I wrote further lines.
Then noticed that I was writing my code outside of the main() function.
Moved the ending curly bracket further and voila.
I am a computer science student learning Java, so I do some work at home and at college on a mixture of Linux and Windows. I have a problem after copying a new project into the Eclipse workspace. The project shows up, but with a red exclamation mark and an error saying:
The project cannot be built until build path errors are resolved
How can I fix this? I tried the solution described here, but it didn't work.
Identify "project navigator" or "package explorer" view.
Right click on your project, select Build Path --> Configure build Path.
In the emerging window, you will find four tabs, select "Libraries".There, under "Web app libraries" (expand it), you will see the libraries added to the project's classpath. Check if all of them are available. If one or more are not (they'll have "missing" beside their name and a red mark on their icon), check if you need them (perhaps you don't); if you don't need them, remove it, if you need them, exit this window, look out for the missing jar and IMPORT it into your project.
Open the Problems view. You can open this view by clicking on the small + sign at the left hand bottom corner of eclipse. It's a very tiny plus with a rectangle around it. Click on it and select problems.
The problem view will show you the problems that need to be resolved.
If the message says "the project is missing the required libraries...", you need to configure your build path by right clicking on your project, selecting properties, then build path. Add the required jar files using the libraries tab.
-If there are other problems other than missing libraries, you need to post the exact problems here to get a precise solution.
If you can't find the build path error, sometimes menu Project → Clean... works like a charm.
In my case, all libraries in the build path were OK.
To solve it, I deleted all project metadata (.project, .classpath, .settings) and re-imported the project as a Maven project.
Right click your Project > Properties > Java Build Path > Libraries
Remove the file with red "X" (something like JRE...)
Add Library
That's how I solved my problem.
I also had this problem in my system, but after looking inside the project I saw the XML structure of the .classpath file in the project path was incorrect. After amending that file the problem was solved.
If not working in any case...then delete your project from the Eclipse workspace and again import as a Maven project if that is a Maven project. Else import as an existing project.
I tried all the previous given solutions, but they didn't work, but it works for me.
In Eclipse, go to Build Path, click "Add Library", select JRE System Library, click "Next", select option "Workspace default JRE(i)", and click "Finish".
This worked for me.
Go to Project > Properties > Java Compiler > Building
Look under Build Path Problems
Un-check "Abort build when build path error occurs"
It won't solve all your errors but at least it will let you run your program :)
Netbeans is not importing a jar from another project. The classpath is fine, the project compiles fine but the editor show several errors in project because it cannot locate classes inside that jar. I've already rebuilded the projects and clean Netbeans' cache (~/.netbeans/7.1.1/var/cache/)
Netbeans version: 7.1.1 and also 7.0
OS version: MacOS 10.7.3
The problem lies with the Netbeans' code editor. My project compiles and it's packaged just fine. I have no problem on that. I have this annoying error messages (eg. red background) in the code editor with no reason.
A workaround I just found: Renaming the dependency project (with refactoring) and adding the new jar to my project do the trick. Still I don't know what happened.
I just had the same problem in NetBeans 7.2.1 today. I could build the project fine but got error markers in the source files and in the Projects tree listings. It seems as if the compiler when you build a project uses a different classpath from the compiler that works in the edit window.
In my case I found we had the same package and class names for different classes in different jars. I don't know if this is relevant or just a red herring.
I still had an error in one project that used these two jars. It seemed like it could only see the classes from the second jar listed in the pom.xml file (we use Maven). I commented out the second jar & rebuilt, then uncommented that second jar & rebuilt and suddenly all of my errors went away.
So I don't have a definite solution but removing and reintroducing a dependency worked for me.
How you import jar file ? You have to right click Libralies in Project Panel and click Add JAR/Folder. And select jar file which you want to import.
I think you have wrongly imported the jar file. Try out the below steps to add jar(s) to your classpath properly.
1. Select your project from the Projects explorer.
2. Right click -> Properties.
3. Select Libraries from Categories list.
4. Click on Add JAR/Folder button.
5. Add your jar(s) & click on OK to finish the process.
Now, it should resolve the reference issues
You mentioned, the editor shows errors because it cannot locate classes inside that jar. Well, are you sure you are using the right jar or right version of jar ? Eclipse is not able to locate any of the classes or only few classes ?
I wish my answer would help fixing the issue (even if too late :) )
Indeed, I have a maven project with two modules. Module1 that contains the class com.x.y.MyClass and Module2 where I'm trying to import com.x.y.MyClass.
It compiles fine, and I can run unit tests using netbeans, but the errors in the editor were embarrassing. So I add Module1 version and packaging type to the pom.xml of Module2 and that fixed my problem (I know, it's very bad to hard code a module version, but at least, I can work without worrying about the editor list of errors)
Cheers !
This is definitely too little too late, but I had this problem today with Netbeans 7.2. All jars were in place, the code was compiling from the build menu, but Netbeans was marking the files in error.
The same exact project was compiling fine with Netbeans 8.0.1.
The problem was with the "Source Root". I clicked on menu Window -> Debugging -> Sources (Alt+Shift+8) and I noticed that I had specified sources on some of the jar dependencies of the project that were no longer valid. Cleaning them up was a 2 step process:
Clean them up from the project files in nbproject dir
Clean them up from
%APPDATA%\NetBeans\7.2\config\Preferences\org\netbeans\modules\java\j2seplatform\Sources.properties
After clean up, I restarted Netbeans and everything was OK.
Hope this helps someone.
I had this issue with few jsf xhtml pages though there wasn't any error in the content of the page. So I opened each page and cut all content, saved the empty file then paste back all content and saved it. it solved the red marking error symbol for me.
I know this question is a bit old but for those who may be facing the same issue currently, hope this will help.
I faced the same challenge after moving my maven projects to a new directory. To fix the issue, I just simply
Renamed the new folder(the one containing my maven projects) just the same name as the previous folder.
Reimported the projects in Netbeans.