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?

12 comments

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!"


2

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

0

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.

0

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

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

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

0

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

4

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

Hi, could you please provide link for the project?

0

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

Invalidate the cache and restart worked for me. 

0

Please sign in to leave a comment.