Intellij can't find classes in same package

Answered

I am using Intellij Community and am having a strange issue.

If a class depends on a class in the same package the ide can't seem to find it.  The class is highlighted in red.  If I explicitly import it instead (I shouldn't have to for classes in the same package) the red goes away.  Building the project seems to be fine and produce no errors.

Anyone seen this before?

27 comments
Comment actions Permalink

Hello Jeffrey,

Have you tried using File | Invalidate Caches and restarting IntelliJ IDEA?

I am using Intellij Community and am having a strange issue.

If a class depends on a class in the same package the ide can't seem
to find it.  The class is highlighted in red.  If I explicitly import
it instead (I shouldn't have to for classes in the same package) the
red goes away.  Building the project seems to be fine and produce no
errors.

Anyone seen this before?

---
Original message URL:
http://www.jetbrains.net/devnet/message/5258389#5258389

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


13
Comment actions Permalink

Select Build -> Rebuild Project, it works for me!

7
Comment actions Permalink

Invalidate the cache and restart worked for me. 

5
Comment actions Permalink

File->Invalidate Cache and Restart worked 4 me... but the issue exists for 10 years without a fix ???

2
Comment actions Permalink

Yep, restarted idea, went to lunch while it reindexed, and same problem reappeared.

1
Comment actions Permalink

I have the same issue with Intellij 9.0.2 Ultimate, Java 1.6.20 on Apple OS X 10.6.2. I have a project with 6 modules and everything was fine until one of the modules started to require importing classes in same package. I have invalidated cached repeatedly with no success. I have checked the Dependencies configuration for modules that work and the modules that exhibit this behaviour, and there is no difference.
Using an ant script to compile works fine.

1
Comment actions Permalink

Denis,
   Raised incident IDEA-55557. The issue can be summarized as attaching the jar file source fin 'B' module to a dependency causes the "cannot find classes in same package issue" in the module 'A' whose source is referenced.

So:
1. module B uses module A jar file (both modules in same project)
2. Open module B dependencies dialog, attach sources to module A source dir
3. open module A in IDE and open a class in any package
4. note that other classes in same package are unresolved and shown as such

Serge

1
Comment actions Permalink

Indeed, I was looking for similar issues as I've just experienced this 'can't access class in same package or even in same class'

I am using an older version (2019.3.5) so not sure whether it'll be fixed here. Anyways, recreating the project from maven source didn't work at first but invalidating cache did.

1
Comment actions Permalink

The issue occurred with one of six modules, so I deleted all but the offending module ('sick' module which cannot find classes in same package) - and the the issue was fixed. I then added the other modules back to the project one-by-one and found the the problem was related to a single module which had a reference to the 'sick' modules source path.

I found in another module this entry in .iml file

<orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="file://$MODULE_DIR$/lib/compile-no-deploy" />
        </CLASSES>
        <JAVADOC />
        <SOURCES>
          <root url="file://$MODULE_DIR$/../SICK_MODULE/src" /> <== this references the the SICK_MODULES source path
        </SOURCES>
        <jarDirectory url="file://$MODULE_DIR$/lib/compile-no-deploy" recursive="false" />
      </library>
    </orderEntry>



When I deleted this reference manually, the problem was fixed:

<orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="file://$MODULE_DIR$/lib/compile-no-deploy" />
        </CLASSES>
        <JAVADOC />
        <SOURCES />
        <jarDirectory url="file://$MODULE_DIR$/lib/compile-no-deploy" recursive="false" />
      </library>
    </orderEntry>

0
Comment actions Permalink

Hi Serge,

Great work!

Please try to work out steps to reproduce the problem behaviour and submit corresponding ticket with that information to IDEA tracker.

Regards, Denis

0
Comment actions Permalink

when i new project from version control , the issue occurred.  i can't fix this issue using File | Invalidate Caches and rebuild project, not only that, the project shows two examples like this "XXX_example(1)". 

0
Comment actions Permalink

Hi, could you please provide link for the project?

0
Comment actions Permalink

the reason of this behaviour is two pom.xm files in a project directory. Please remove dependency-reduced-pom.xml before importing the project.

0
Comment actions Permalink

worked for me.Thanks a ton!!!!!!!!!!!

0
Comment actions Permalink

Had exactly the same problem and answer from Dmitry Jemerov Created March 11, 2010 19:29


" Have you tried using File | Invalidate Caches and restarting IntelliJ IDEA? "

 

did work perfectly. Thanks

0
Comment actions Permalink

I am suffering from this issue and unfortunately invalid caches and restarting is not working for me.

0
Comment actions Permalink

Could be the https://youtrack.jetbrains.com/issue/IDEA-220511 The fix will be available in the next 2019.3.X version update.

Please try it with 2020.1 EAP version from https://confluence.jetbrains.com/display/IDEADEV/IDEA+2020.1+latest+builds

If issue remains submit a request at https://intellij-support.jetbrains.com/hc/en-us/requests/new with the sample project and IDE logs zipped (Help | Compress Logs and Show in ... action).

0
Comment actions Permalink

In my case (using gradle) these steps helped resolve this issue:

make sure the source files are in {project root - build.gradle folder}/src/main/java/{top package e.g. com}

0
Comment actions Permalink

Invalidate the cache and restart worked for me. 

Thanks
0
Comment actions Permalink

Is this there a ticket to fix this bug? It is ridiculous and has been around for months for me now. Yes Invalidating Caches and Restart works, but this problems happens for me at least twice a day if not more often. Then re-indexing takes minutes or a lot longer for bigger projects; what's worse is it invalidates caches for all projects not just the one so all projects must be indexed.

After the restart and indexing though it also requires me to refresh the dependencies which takes another few minutes. This is just ridiculous. Does anyone have anything more helpful or at least a sign that this is being worked on?

Thanks :)

EDIT: oh also, when it can't access a class it just can't access that class period; even from within the actual class.

0
Comment actions Permalink

Mark Vogel1

>Is this there a ticket to fix this bug?

See IDEA-244761, for instance. The symptoms are similar.

That said, the actual reason can be different in your case. We will be able to analyze it if you submit a new support request attaching a demo project to reproduce the issue on, and zipped log folder (Help | Collect Logs and Diagnostic Data menu option).

0
Comment actions Permalink

Arina Efremova 

The above ticket IDEA-244761 doesn't seem to exist or not visible for me

0
Comment actions Permalink

vali

Indeed, it was created as private so as to avoid log exposure.

If you have a similar issue and have tried all suggestions from this thread to no avail, please submit a new support request attaching a demo project to reproduce the issue on, and zipped log folder (Help | Collect Logs and Diagnostic Data menu option).

0
Comment actions Permalink

The same problem with version 2020.2.3 Ultimate. Like 10 years after the first comment here. I have never had simmilar problem with Eclipse ;) 

0
Comment actions Permalink

Peter Varga Have you tried to invalidate caches and restart? If you have a similar problem, please follow the instructions Arina mentioned on September 30, 2020. Our support team will be glad to help you deal with that.

Thank you!

0
Comment actions Permalink

@Egor Klepikov yes, I tried it, and it solved the problem. But come on guys. It takes several minutes. 

0

Please sign in to leave a comment.