Problem
Java built-in and external library classes are highlighted in red color with errors such as "Cannot resolve symbol 'String'". I am still able to compile and run the Java class, but not able to use method completion or other JDK help.
- This happens for both JDK 8 and JDK 11.
- This issue persists across multiple project types (Maven, Gradle, and plain IDEA Java project).
- Happens both with an existing project and a brand new Hello World project I created from scratch.
- Tried multiple troubleshooting steps I found on the IntelliJ website (e.g. https://www.jetbrains.com/help/idea/sdk.html) and on the web.
- Verified JDK settings in all JDK-related fields under File -> Project Structure.
- Used "File -> Invalidate Caches / Restart ..." after making changes in Project Structure settings.
If the external library classes can't be resolved, it may look like this(notice that the class files have a text icon shown but not a class file icon):
Resolution
Removing *.class from File | Settings> Editor > File Type > ignored file and directory > removed *.class files fixed this issue.
Under File | Preferences... -> Editor -> File Types -> Ignore files and folders, the list included .class (as in `.class;*.hprof;*.pyc;*.pyo;*.rbc;*.yarb;*~;.DS_Store;.git;.hg;.svn;CVS;pycache;_svn;vssver.scc;vssver2.scc;`).
Or assign *.class file to other file types like Text, this will also cause the issue. Please make sure it's marked as Java Class files under File | Settings> Editor > File Type > Recognized File Types.
The correct assignment should look like this:
The external libraries or the class file icon should look like this:
Ref:
Java built-in classes are highlighted in red color with errors such as "Cannot resolve symbol 'String'" if *.class is added to Ignore files and folders Cannot resolve Symbol: JDK-provided classes not recognized Cannot resolve classes: IDE fails to find standard and external library symbols
Comments
0 comments
Please sign in to leave a comment.