Java App - shows "Cannot resolve symbol" but App Compiles

Answered

I am working on a Java app with some example code I downloaded from Google and on many of the import statements and some variable definitions the UI shows the text in red with “Cannot resolve symbol” errors if I hover over the red text.

It was very frustrating because I thought my code was broken but I loaded it into another IDE and it didn't show the errors.

The app compiled and ran so I went back to IntelliJ

Is this some setting I need to change?

Thanks

Rich

0
3 comments

Hello Richard Morey 

What you are seeing usually means that IntelliJ IDEA’s code analysis doesn’t have the same project configuration as the compiler, so the editor can’t resolve some classes or variables even though the project still compiles.

Please try the following checks:

  • If the project uses Maven or Gradle and contains a pom.xml or build.gradle, close the current project in IntelliJ IDEA, and re‑open it by selecting that file (not just the folder). This lets IntelliJ IDEA import the project model and dependencies correctly.
  • Go to File | Project Structure | Project and make sure a valid Java SDK is selected, then in Modules verify that the same SDK is set for the module.
  • In Project Structure | Modules | Sources, make sure your src (or equivalent) folder is marked as Sources (blue folder). If the files are under a plain directory not marked as a source root, the editor won’t be able to resolve symbols properly.
  • If the project structure looks correct, try File | Invalidate Caches… | Invalidate and Restart to rebuild the indexes.

If the issue persists after these steps, please share:

  • A screenshot of the Project Structure (Project and Modules pages).
  • A screenshot of the editor showing one of the unresolved imports together with the Project tool window.
  • The Problem tool windows showing the error details.
  • The IDE logs collected via Help | Collect Logs and Diagnostic Data.

Attach the zip file via our secure upload site https://uploads.jetbrains.com/, and share the uploadID. With that information, I'll see exactly how the project is configured and pinpoint why the editor can’t resolve the symbols while the code still compiles.

0

This worked, thanks!

0

Hi Richard Morey 

Thanks for confirming it worked!

Have a great day!

0

Please sign in to leave a comment.