Cannot resolve symbol

Answered

I've run into a bizarre problem where IDEA tells me that it cannot resolve symbol for classes within the same package as the class open in the editor. And, if I use Alt-Enter to add an import line, the import line shows up as greyed-out for 'unused import statement' (but the 'cannot resolve symbol' flag goes away). Similarly, there are a number of classes being flagged with cannot resolve symbol while there's a greyed-out import line that contains a wild-card import that includes those flagged classes.

This is in IDEA 9.0.4 and only just started happening.
Invalidating the caches did not fix the problem
Deleteing the cache files in the filesystem did not fix the problem
Deleting the module and rebuilding it did not fix the problem

Any other ideas?

0
35 comments

Which languages are these classes written in? Are they located under a source root? Are they in the same module? Do they have correct package statements? Is the same problem present in IDEA X?

0

These are Java classes.
They live in a subdirectory of a directory marked source in the module settings (which I what I'm guessing you mean by source root - and I checked to make sure I hadn't accidentally excluded that subdirectory)
They are in the same module
They have correct package statements
I have not tried this in IDEA X as getting work done is more pressing right now

Also...
This is a problem I've never seen in IDEA before (and I've been using it since 5 or 6)
Some classes from within the same module are imported without problem
However, when I changed one of those imports to a wild card, the Auto Import feature added a FQN import and the wild card import ended up greyed-out as another 'unused import statement'

0

Do you have multiple classes with the same short name (in different packages)?

0

Nope - no short name collisions

0

Could you please attach your logs (see http://devnet.jetbrains.net/docs/DOC-181) and some screenshots of the errors? Does this happen in one particular project or in all? It would be great if you could provide a project with this problem for us to reproduce the problem.

0

Here's a zip of the log directory - the last things I did was to open a file demonstrating the problem and then close IDEA

On providing a project - would sending you the .idea project dir and module .iml files help without having the relevant source code?



Attachment(s):
log.zip
0

I see you're using some 3d party plugins. Could you please try disabling them (in particular FindBugs) and see if the problem persists. If yes, then please attach the *.iml files.

0

I've emailed those iml files to you.
Thank you for the persistent followup

0

Were you able to solve this problem? I have the same trouble.

0

Not yet. I need some sample project to be able to fix it.

0

Did you kill IDEA through the task manager?  I've seen this problem, especially in IDEA 10, after I have had to kill the process.

0

I started seeing the problem after my computer powered off spontaneously while IDEA was updating the project (the power off had nothing to do w IDEA, faulty laptop docking station) - my project got corrupted and I had to rebuild it. Ever since then, I've had this problem.

Afa providing a project, I'm not sure I could repro the problem and the project that has the problem contains proprietary code.

0

Hello Andy,

Are you certain that File | Invalidate Caches doesn't help?

I started seeing the problem after my computer powered off
spontaneously while IDEA was updating the project (the power off had
nothing to do w IDEA, faulty laptop docking station) - my project got
corrupted and I had to rebuild it. Ever since then, I've had this
problem.

Afa providing a project, I'm not sure I could repro the problem and
the project that has the problem contains proprietary code.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


1

Yes, and I've also tried removing the cache files directly in the file system

0

Could it be that your project has a library whose classes or source roots point to somewhere inside the project (e.g. another module)?

0

I know this is a little late, and hopefully you already found a solution, but I'll post this any way as I just ran into this exact problem and found a solution (that at least worked for me).  Hopefully this will save someone else an afternoon of frustration.

I had the exact same symptoms as Andy, nearly suddenly certain classes could not be found, even though the files were obviously there.  For many of the cases, the classes were actually in the same package.  I noticed that while the parent directories were all listed as sources, certain, nearly random subdirectories were not.

Like Andy, I removed the module from my project, invalidated the caches, physically deleted the cache files, restared IntelliJ, and then re-added the module.  Unfortunately, this did not resolve the problem.  I found that if I also removed the index and localhistory files, then restarted IntelliJ and re-added the module, that made IntelliJ rebuild everything and all my packages could be found.

0

Even this is very late I will share it with you.

I got the same problem, but also with methods in super classes.
My project compiles and runs even I can't see everything in the JDE.
It started with v10 community, I then went to v10 Ultimate, still same problem, then v11 ultimate no change.
Opening the same project in community v9 everything is as expected, therefore I suspect v10 and above to have a bug.
I have tried to invalidate, clear out files etc. no luck.
Please bear with me, I'm pretty new to this - so my explanition migth not be to clear.
I then looked at the hierachrcy and it appears it happens when a class extend another class not in the project, but taken from a jar. All classes are in the same package.

Examples.
class C extends Class B extends class A
Class C has a problem seing methods and symbols in class A, as class B is taken from a jar, then class A is also taken from that jar, despite A exist in the prjoect.

class E extends Class D extends class A
Here we have no problem seing what's in A, as class D is in the project.

So to me it looks like the resolver gets side tracked if it has to go to a jar and then can't get back into the project.

This might not be the right place to put it - please guide if this is the case.

0

Jan, if you please create a small sample project demonstrating the issue? I can't reproduce it so far.

0

Hi you all,
I have a similar problem.
I have a multi-module project that i imported from Eclipse to IDEA.  In this project every module compiles and runs just perfect but there is one GWT module just doesn't compile. IDEA refers to wrong method. However Eclipse finds the correct one.
Let me explain the problem: I have a class named KeysMenuRoleListPage. This class has an inner class named AdMenuBaseTreeLoader which extends BaseTreeLoader. This BaseTreeLoader class is in gxt.jar (GWT GXT library). BaseTreeLoader also extends BaseLoader (it is in that jar as well). In my KeysMenuRoleListPage class, i call a method which is in BaseLoader class. But IDEA tries to find this method in BaseTreeLoader and gives compile error. It sould have referred to BaseLoader.
I did everything that is being adviced in this thread. No luck.
I created a simple project to regenerate to problem. I am enclosing the project, IDEA's logs and necessary libraries. gxt.jar and gwt-user.jar
I am using 10.5.4 Ultimate. The problem exists with IDEA 11 Ultimate also. My OS is Win7 x86.
I hope this helps you, and you solve it soon.



Attachment(s):
idea-error.7z.zip
0

Hamza, your project just fails to be compiled by javac. com.extjs.gxt.ui.client.data.BaseTreeLoader#onLoadSuccess expects some ModelData variable in its first argument, but you pass Object there. Try adding some type parameters. As far as I see, IDEA does everything right, it issues exactly the same errors as javac.

0

oh, well, it trimmed down the project. Let me try to reproduce the error.

0

Peter, when i follow the reference of onLoadFailure(config, arg0); method call with Ctrl+click in Eclipse, it tooks me to BaseLoader.onLoadFailure(C loadConfig, Throwable t) method decleration and no error is produced. Any IDEA? :)

0

Hamza,

when I do the same in IDEA, I get to protected void onLoadFailure(M loadConfig, Throwable t) in BaseTreeLoader, which overrides the method you get navigated to. That's actually a quite nontrivial resolution problem with generics and raw types, and I'm not surprised that Eclipse compiler has different opinion about it. Different compilers have different behaviour and different bugs in relation to the spec. IDEA takes javac as de-facto standard and behaves in the same way. If you specify type parameters for BaseTreeLoader correctly, the compilation should pass. And after that there's a higher probability that Eclipse will behave similar to IDEA and javac.

0

Hi Peter,
Thank you for your instant replies. Finally I am able to run my application. Keep up the good work on IDEA. Thank you again.

0

Did this ever get solved?  Six years later and  I have this exact issue.  The code complies fine but IntelliJ tells me that it "Can't resolve symbol" for every class in every subdirectory of the main source package.

 

Thanks for any advice,

Tom S.

0

Tom, each such symptom can be caused different underlying issues. First, please try File | Invalidate Caches. If this doesn't help, the best way to resolve this is to provide as many details as possible (idea.log (Help | Show Log...), screenshots, a sample project if possible), preferably in a new bug ticket (https://youtrack.jetbrains.com).

0

Thanks for thee response.

 

I did try invalidating the caches and that didn't help.

Having said that, I did solve this issue though I still don't know what caused it.  Moving all of the files to the package source root, deleting the directories, recreating the directories (i.e. packages), then moving the files back resolved the errors.

 

Thanks, again.

Tom S.

0

May 2018 and I have the same d*** problem. Most vexing. I can't import packages in the same directory into my project. IntelliJ, please fix this time-wasting issue. See this image file
 

0

I think I finally found a way. Click on the first instance fo the class error (in the code, not in the imports.) Choose import class.

 

IJ must be able to make this easier.

0

After I attempted to add the AssertJ library to my project for testing, some configuration in my project changed and I cannot import any classes from my main package into my JUnit tests.

My Main Class runs as expected, but I can no longer run any tests requiring Classes from the main package.

I've tried the following:

  • Removing AssertJ import
  • Rebuild Project
  • Refresh All Gradle Projects
  • Invalidate IntellIJ cache an Restart from Settings
  • Deleting project locally and re-downloading from GitHub

0

Please sign in to leave a comment.