4

IntelliJ IDEA 2017.2

I know this has been asked, but I have tried every fix I could find, as shown below.

Every symbol in my java code has an error Cannot resolve method, or Cannot resolve symbol. However, the code still compiles and runs with 0 errors. The error messages in the IDE started the first time I opened the project, on 3 separate computers, but runs fine on a fourth....I can't find anything different on that fourth computer.

I have following the following instructions from this issue:

File -> Invalidate Caches / Restart

I deleted the [IDEA system](https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs) directories, and re-imported the Maven project.

I have re-imported the Maven project

I re-imported the project with auto-import

I also followed the instructions from this issue:

File -> Synchronize

then

File -> Invalidate Caches / Restart

As well as the solutions here:

Check source roots

Ctrl+Alt+Shift+S

There were no errors or fixes in the Module source roots, or the module dependencies.

I also tried re-importing with "Search for projects recursively" checked as recommended here.


Edit1

This isn't a screenshot from my actual code, but my errors look the same as the screenshots from this post.

enter image description here

EDIT2

I just found an error I hadn't seen before. When I go to Project Structure (Ctrl+Alt+Shift+S), under Libraries, I see the following errors.

enter image description here

I checked on the location shown /home/user/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7-sources.jar and it doesn't exist. I have antlr-2.7.7.jar, but I'm not sure if I need to download the antlr-2.7.7.7-sources.jar, or just point my Library to the .jar I have (as I'm unfamiliar what these settings do)

trueCamelType
  • 2,198
  • 5
  • 39
  • 76
  • Have you tried creating a new project? – Charlie Aug 03 '17 at 04:32
  • Not yet. The project is pretty massive, but that will probably be my next step if there's no solutions recommended here. – trueCamelType Aug 03 '17 at 04:33
  • can you post some screenshot ? – John Joe Aug 03 '17 at 04:34
  • Added in an edit. Not my code, but literally every file, every line with a method or symbol is underlined in red. – trueCamelType Aug 03 '17 at 04:38
  • look like you are using maven and you have to update pom.xml – John Joe Aug 03 '17 at 04:44
  • have you added SLF4J to your Maven Project? – John Joe Aug 03 '17 at 04:45
  • What happens if you run `mvn clean install` from the command line? – Val H Aug 03 '17 at 04:55
  • @ValerieHouseman mvn clean and install both run with full success. No issues. – trueCamelType Aug 03 '17 at 14:02
  • @JohnJoe I dont' think it's an issue with the pom.xml file because we have another dev who can run everything fine with no errors in his intellij. Having said that, I'm still going through and making sure all the versions actually match in the pom file. – trueCamelType Aug 03 '17 at 14:06
  • @trueCamelType have you set your language level to the correct JDK level? https://stackoverflow.com/questions/29915259/how-to-change-project-language-level-for-all-project-in-intellij – Novaterata Aug 03 '17 at 15:00
  • @trueCamelType I see a root pom.xml and several directories also with maven projects defined by a pom.xml When you build all of these projects, what is your sequence? Do some depend on others? – Val H Aug 15 '17 at 21:40

5 Answers5

4

The answer was the look through the pom.xml file line by line, and see what the dependencies were that I didn't have. I thought it was a configuration issue, but it wasn't.

I didn't notice that I didn't have the lombok plugin, which was a dependency for my project.

The problem listed in EDIT2 wasn't actually an issue since all of the classes were available.

trueCamelType
  • 2,198
  • 5
  • 39
  • 76
2

Since your project compiles and runs successfully with mvn clean install, you know your pom is valid.

Given that, I would recommend to:

  1. CloseIntelliJ
  2. delete the .idea directory and any *.iml, *.ipr files for each of your modules. Don't worry, IntelliJ will re-create them. Back them up by renaming them if you're really concerned.
  3. Open IntelliJ and find the new project wizard.
  4. Find the option to import from an existing maven project
  5. Select the pom for your root project
Val H
  • 507
  • 4
  • 13
1

Check if module settings are correct. Open Project structure (Ctrl+Alt+Shift+S) and check the source directory settings under Source Tab are valid.

mx0
  • 6,445
  • 12
  • 49
  • 54
  • @trueCamelType Check if you corresponding dependencies in place and check the Java version as well and language settings – Anil Kumar Athuluri Aug 03 '17 at 14:08
  • I just looked in libraries under Project Structure (Ctrl+Alt+Shift+S) and found that my sources and javadocs are red. I'll add a screen shot to my question. I'm not 100% sure if I should just change those, or download the sources. – trueCamelType Aug 03 '17 at 14:15
  • @trueCamelType also, click on little refresh icon under maven tab – Anil Kumar Athuluri Aug 03 '17 at 14:15
  • @trueCamelType Glad you found something wrong under project structure. Please up vote and accept my answer if it helped you. – Anil Kumar Athuluri Aug 03 '17 at 14:33
  • Thanks for helping me find the error. I'm still not sure how to resolve this. Definitely an upvote though. – trueCamelType Aug 03 '17 at 14:46
  • @trueCamelType mouse hover on error and Alt+Enter and follow what it says .., – Anil Kumar Athuluri Aug 03 '17 at 14:59
  • There is no alt+enter option inside of the libraries, but in the errors in the actual code, it just asks if it wants me to create the class/method/symbol that already exists. – trueCamelType Aug 03 '17 at 15:53
  • @trueCamelType, Yeah I meant in the code..so looks like it's not picking up the dependencies hence asking to create the class. Have you tried to reimport dependencies by clicking on little refresh icon under Maven projects tab. – Anil Kumar Athuluri Aug 03 '17 at 15:57
  • I'm not sure where the Maven Projects tab is, but under Project Structure, there is a Project tab, but nothing about maven there. I have, however, reimported this entire project into maven 10's of times. – trueCamelType Aug 03 '17 at 15:59
  • 2
    @trueCamelType View > Tool Windows > Maven Projects – Anil Kumar Athuluri Aug 03 '17 at 16:01
  • @trueCamelType, Also try to delete that correpsonding depenendices in .m2 and rebuild the app so it would reinstall in .m2. Also check if you updated your credentials and forgot to change in settings.xml (incase you are connecting to org's internal repo) – Anil Kumar Athuluri Aug 03 '17 at 16:05
  • Yes, I have done both of those, with the same errors. Deleted the dependencies directory inside of .m2 and refreshed maven now (thinks for instructions). And I'm not set up to an internal repo. – trueCamelType Aug 03 '17 at 16:12
0

This is a weird one. I faced the same issue and went through all questions on stackoverflow and other forums and applied all suggestion to an extent to reinstalling intelliJ.

Though what problem in my case was that i had excluded some files namely .gradle and build folder, which definitely sounds important. I must have done this get excluded for git status notifs but somehow i had excluded it from my project as i am new to intellij. To check if any of your folders are exclude goto -> modules CTRL + Shift +Alt + s and check for any red items you should probably include the ones necessary here.

Hope this helps few of those out there.

Bimal Gupta
  • 71
  • 1
  • 3
-1

you are using maven project, delete .m2 folder and update maven project and clean the project the rebuild it and run it... some time maven project occur that type of issue, which resolve by rebuilding the project. also check the version of your dependency.

Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17