IntelliJ cannot find any declarations

2019-03-08 00:24发布

I completely uninstalled IntelliJ and have now reinstalled and imported my project. I imported using gradle and can see all of the files in my project present. However, when I open a file I can't find any declaration to go to by doing cmd + click. I have the Java 7 SDK setup, and I can't even go to the declaration of classes in my own project. Going to a Java core class like String or List doesn't work either. How can I enable the IDE to be able to find my classes?

I'm on OSX Yosemite, IntelliJ 2016.1.2 build 145.972.

15条回答
时光不老,我们不散
2楼-- · 2019-03-08 00:44

Ensure that the directory which contains your compiled classes and libraries is marked as sources Root.

查看更多
倾城 Initia
3楼-- · 2019-03-08 00:45

I had the same issue with idea and I was trying to open a maven project but the pom files where not identified. So right clicking on the pom file and choosing "add as maven project" did all the magic for me :)

查看更多
迷人小祖宗
4楼-- · 2019-03-08 00:48

Had the same problem. But only on my own methods.
Just fixed it by invalidating cache: (File-> Invalidate Caches/Restart)

查看更多
乱世女痞
5楼-- · 2019-03-08 00:48

Same Problem for Python Project!!!

I tried to make a clean new intellij project and updated everything. Tried different virtualenvs but nothing worked out.

UNTIL I uninstalled the Python Plugin + Restart IntelliJ + Intall Python Plugin + Restart IntelliJ again. I'm not sure if this is a "real" solution, but it solved my issue.

Maybe you can try something familar for Java "Plugin"/JDK?

查看更多
女痞
6楼-- · 2019-03-08 00:49

I faced the same issue and spent almost 15-16 tiring hours to clean, rebuild, invalidate-cache, upgrade Idea from 16.3 to 17.2, all in vain. We have a Maven managed project and the build used to be successful but just couldn't navigate between declaration/implementations as Idea couldn't see the files.

After endlessly trying to fix this, it finally dawned to me that it's the IDEA settings causing all the headache. This is what I did (Windows system):

  1. Exit IDE
  2. Recursively delete all .iml files from project directory del /s /q "C:\Dev\trunk\*.iml"
  3. Find and delete all .idea folders
  4. Delete contents of the caches, index, and LocalHistory folders under .IntelliJIdea2017.2\system
    1. Open Idea and import project ....

VOILAAAAAAAAAAAA...!! I hope this helps a poor soul in pain

查看更多
该账号已被封号
7楼-- · 2019-03-08 00:50

If you see red circle on the icon of Java files, and got warning like "cannot find declaration to go to". Then you can do something below:

  1. Right click root folder of your project/module.
  2. Mark Directory As -> Excluded.

enter image description here

It works for me. in Windows 7, Intellij 2016.1.1

查看更多
登录 后发表回答