简体   繁体   English

IntelliJ 找不到任何声明

[英]IntelliJ cannot find any declarations

I completely uninstalled IntelliJ and have now reinstalled and imported my project.我完全卸载了 IntelliJ,现在重新安装并导入了我的项目。 I imported using gradle and can see all of the files in my project present.我使用 gradle 导入,可以看到我项目中的所有文件。 However, when I open a file I can't find any declaration to go to by doing cmd + click.但是,当我打开文件时,通过执行 cmd + 单击找不到任何对 go 的声明。 I have the Java 7 SDK setup, and I can't even go to the declaration of classes in my own project.我有 Java 7 SDK 设置,我什至不能 go 在我自己的项目中声明类。 Going to a Java core class like String or List doesn't work either.转到 Java 核心 class 像StringList也不起作用。 How can I enable the IDE to be able to find my classes?我怎样才能使 IDE 能够找到我的课程?

I'm on OSX Yosemite, IntelliJ 2016.1.2 build 145.972.我在 OSX Yosemite 上,IntelliJ 2016.1.2 build 145.972。

I had this same problem, and @AniaG's solution in the comments worked for me.我遇到了同样的问题,@AniaG 在评论中的解决方案对我有用。

  • Right-click src folder右键单击src文件夹
  • Mark Directory as > Sources Root将目录标记为>源根

在此处输入图片说明

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.我遇到了同样的问题,花了将近 15-16 个小时来清理、重建、使缓存失效、将 Idea 从 16.3 升级到 17.2,但都是徒劳的。 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.我们有一个 Maven 管理的项目,并且构建曾经是成功的,但由于 Idea 看不到文件,因此无法在声明/实现之间导航。

After endlessly trying to fix this, it finally dawned to me that it's the IDEA settings causing all the headache.在无休止地尝试解决此问题后,我终于明白是 IDEA 设置导致了所有头痛。 This is what I did (Windows system):这就是我所做的(Windows系统):

  1. Exit IDE退出IDE
  2. Recursively delete all .iml files from project directory del /s /q "C:\\Dev\\trunk\\*.iml"从项目目录中递归删除所有.iml文件 del /s /q "C:\\Dev\\trunk\\*.iml"
  3. Find and delete all .idea folders查找并删除所有.idea文件夹
  4. Delete contents of the caches, index, and LocalHistory folders under <user_home>\\.IntelliJIdea2017.2\\system删除<user_home>\\.IntelliJIdea2017.2\\system下的 caches、index 和 LocalHistory 文件夹的内容
  5. Open Idea and import project ....打开Idea并导入项目....

VOILAAAAAAAAAAAA...!!呜呜呜呜呜呜呜呜呜呜呜呜!! I hope this helps a poor soul in pain我希望这能帮助一个痛苦的可怜灵魂

I had the same issue with idea and I was trying to open a maven project but the pom files where not identified.我有同样的想法问题,我试图打开一个 Maven 项目,但未识别 ​​pom 文件。 So right clicking on the pom file and choosing "add as maven project" did all the magic for me :)因此,右键单击 pom 文件并选择“添加为 maven 项目”对我来说非常有用:)

Had the same problem.有同样的问题。 But only on my own methods.但仅限于我自己的方法。
Just fixed it by invalidating cache: (File-> Invalidate Caches/Restart)只是通过使缓存无效来修复它:(文件-> 使缓存无效/重新启动)

I was having similar issues in my IntelliJ mvn project.我在 IntelliJ mvn 项目中遇到了类似的问题。 Pom.xml was not recognized.无法识别 Pom.xml。 What worked for me was right click on the pom.xml and then add as a maven project.对我有用的是右键单击 pom.xml,然后添加为 maven 项目。

Most of the times there has been a problem with building the cache of the IDE, or something related.大多数情况下,构建 IDE 的缓存或相关问题都存在问题。

Most probably, File -> Invalidate Caches / Restart , will resolve this problem, just let the IDE finalize it's caching.最有可能的是, File -> Invalidate Caches / Restart ,将解决这个问题,让 IDE 完成它的缓存。

右键单击您的 src 文件夹并选择选项“标记目录为”--“源根目录”,然后再次右键单击您的项目并选择“重新格式化代码”(在此下也选择清理代码),这将工作正常。

If you see red circle on the icon of Java files, and got warning like "cannot find declaration to go to".如果您在 Java 文件的图标上看到红色圆圈,并收到“找不到要转到的声明”之类的警告。 Then you can do something below:然后你可以在下面做一些事情:

  1. Right click root folder of your project/module.右键单击项目/模块的根文件夹。
  2. Mark Directory As -> Excluded.将目录标记为 -> 已排除。

在此处输入图片说明

It works for me.它对我有用。 in Windows 7, Intellij 2016.1.1在 Windows 7 中,Intellij 2016.1.1

Your source folders where your Symbols are (Classes) are need to be configured as "Content Root".您的符号所在的源文件夹(类)需要配置为“内容根”。

  • Open Project Structure: # ;打开项目结构: # ;
  • Click Modules单击模块
  • You can configure your Content Root (Sources, Tests, Resources etc) for each module that you want to Navigate to.您可以为要导航到的每个模块配置内容根(源、测试、资源等)。

Once done you should be able to navigate to your symbols.完成后,您应该能够导航到您的符号。

I got this problem on Big Sur.我在 Big Sur 上遇到了这个问题。 Solution: File -> Invalidate Caches.解决方案:文件 -> 使缓存无效。 After that press Option + Enter on every red field.之后,在每个红色字段上按 Option + Enter。

I found this cannot find declaration to go to problem once in my Maven project.我发现这在我的 Maven 项目中cannot find declaration to go to一次解决问题的cannot find declaration to go to The reason for this was just that one of the sub-projects in my project did not import as maven project correctly.原因只是我项目中的一个子项目没有正确导入为 maven 项目。

In my case, I just updated my IntelliJ to Ultimate 2018.2 and all of my projects suddenly cannot find the implementations and the 'src' folders - it turned out IntelliJ removed the type of project (eg Maven).就我而言,我刚刚将 IntelliJ 更新到 Ultimate 2018.2,我的所有项目突然都找不到实现和“src”文件夹 - 结果 IntelliJ 删除了项目类型(例如 Maven)。

What I did is:我所做的是:

Right click on the root project > Add Framework support... > Look for Maven (in my case) > Wait to re-index again > Then it worked again.右键单击根项目> 添加框架支持...> 查找 Maven(在我的情况下)> 等待再次重新索引> 然后它再次工作。


UPDATE 2:更新 2:

I have always been encountering this when I update IntelliJ (2019.1.1 Ultimate Edition).我在更新 IntelliJ(2019.1.1 Ultimate Edition)时一直遇到这个问题。 Just click the refresh button of Maven Tab and it should re-index your current project as Maven Project:只需单击 Maven 选项卡的刷新按钮,它就会将您当前的项目重新索引为 Maven 项目:
在此处输入图片说明

确保包含已编译类和库的目录被标记为源根。

One of the reason can be that it is not able to detect the pom.xml(or gradle file) and thats why not able to set it as a maven project(or gradle).原因之一可能是它无法检测 pom.xml(或 gradle 文件),这就是为什么不能将其设置为 Maven 项目(或 gradle)的原因。

You can manually set it up as a maven(or gradle) project by selecting your pom.xml(or gradle file)您可以通过选择 pom.xml(或 gradle 文件)手动将其设置为 maven(或 gradle)项目

IDEA may ignore some of your maven dependency files. IDEA 可能会忽略您的某些 maven 依赖文件。 The "External Libraries" node in your project structure might be empty or incomplete.项目结构中的“外部库”节点可能为空或不完整。

Go to:前往:

  1. IntelliJ --> Preferences IntelliJ --> 首选项
  2. Search for Maven [on the left tab] -> Ignored Files搜索 Maven [在左侧选项卡上] -> 忽略的文件
  3. See if there is any path on the right side that is checked(ignored) and uncheck that.查看右侧是否有任何路径被选中(忽略)并取消选中。 在此处输入图片说明

Came across the same issue and in my case (Java project), I had to include all the dependent jars in the project's libraries section.遇到了同样的问题,在我的情况下(Java 项目),我必须在项目的库部分包含所有依赖的 jar。

File -> Project Structure -> Libraries文件 -> 项目结构 -> 库

I had to add my project dependent jars in the above section (for example; project/web/lib/).我必须在上面的部分中添加我的项目相关 jar(例如;project/web/lib/)。 After doing so, all resolved fine.这样做之后,一切都解决了。 I hope this will help someone.我希望这会帮助某人。

I too faced this issue.我也遇到过这个问题。 I've tried the solutions mentioned here.我已经尝试过这里提到的解决方案。 The issue seems not with the source folder.问题似乎与源文件夹无关。

For me the issue occurred when I installed a new version of IntelliJ, was using 2019 version moved to 2020 version.对我来说,当我安装新版本的 IntelliJ 时出现问题,使用 2019 版本移至 2020 版本。 The project got opened in the new version but the declarations were missing.该项目在新版本中打开,但缺少声明。

I fixed this by :我通过以下方式解决了这个问题:

 - File>Project Structure. - Under Project Settings go to Modules. Here you should see the different project folders, for me it was not there. - Click the + button on top and click Import Module. - Select the root pom.xml and wait for the indexing to complete.

After the indexing is done all the declarations were working.索引完成后,所有声明都在工作。

我在 Goland JetBrain 上遇到了类似的问题,对我有用的类似于@user8382868 所说的,但我只关闭了 IDE,将文件夹.idea文件重命名为.idea.old ,重新打开项目后一切正常。

For Java based project, this is what worked for me :-对于基于 Java 的项目,这对我有用:-

-Download Intellij 2020.3.4 version instead of 2021.1.1
-Add configuration, plugins.
-Configure settings, Project Structure
-Right click on the root folder -> Mark Directory as -> Sources Root
-File -> Invalidate caches/restart -> Invalidate and Restart

None of the methods listed in this channel works for me.此频道中列出的方法均不适合我。 However, I am able to resolve it using the following method, and I hope that it works for you too.但是,我可以使用以下方法解决它,我希望它也适用于您。

Right Click the pom.xml file and then select "Maven". After that, click "Import Maven Project"

In my case I was using a gradle project with subprojects.就我而言,我使用的是带有子项目的 gradle 项目。 The reason IntelliJ couldn't find declarations was that the subprojects were not built. IntelliJ 找不到声明的原因是未构建子项目。

After investigating why subprojects were not built, I found out that using "auto-import" was breaking the subprojects.在调查了为什么没有构建子项目之后,我发现使用“自动导入”会破坏子项目。

After importing the project from build.gradle without auto-import , it worked for me.没有 auto-import 的情况下build.gradle导入项目后,它对我build.gradle

就其价值而言,在 Pycharm 中它是:右键单击根文件夹-> 将目录标记为-> Sources Root

Same Problem for Python Project!!! Python项目同样的问题!!!

I tried to make a clean new intellij project and updated everything.我试图创建一个干净的新 Intellij 项目并更新所有内容。 Tried different virtualenvs but nothing worked out.尝试了不同的 virtualenvs,但没有任何效果。

UNTIL I uninstalled the Python Plugin + Restart IntelliJ + Intall Python Plugin + Restart IntelliJ again.直到我卸载了 Python 插件 + 重新启动 IntelliJ + 安装 Python 插件 + 再次重新启动 IntelliJ。 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?也许您可以尝试一些熟悉的 Java“插件”/JDK?

In my case, none of the above helped.就我而言,以上都没有帮助。 Only upgrade of Intellij from 2017.3 to 2018.2 helped.只有将 Intellij 从 2017.3 升级到 2018.2 才有帮助。

Do not try 2018.1 as it had a bug wherein the Find files popup would not come up.不要尝试 2018.1,因为它有一个错误,其中“查找文件”弹出窗口不会出现。

For someone whom the above solution didn't worked.对于上述解决方案不起作用的人。

For gradle,对于gradle,

File -> Project Structure文件 -> 项目结构

Click on Project Under Project Settings单击项目项目设置

Update Project Language level as Modules, private methods in interfaces etc.项目语言级别更新为模块、接口中的私有方法等。

Click OK and Import Gradle Settings单击确定并导入 Gradle 设置

项目结构

Somehow I set my Maven modules to be ignored.不知何故,我将我的 Maven 模块设置为被忽略。 In the Maven tool window right click and select 'Unignore Projects'.在 Maven 工具窗口中右键单击并选择“Unignore Projects”。

Then all the directories will be automatically selected.然后将自动选择所有目录。

在此处输入图片说明

在此处输入图片说明

Importing my project (which had 3 different modules in it) - as File -> Module From Existing Sources fixed it for me.导入我的项目(其中包含 3 个不同的模块) - 作为文件 -> 来自现有源的模块为我修复了它。

I was facing the same issue, so here are the steps I followed:我遇到了同样的问题,所以这里是我遵循的步骤:

  1. Right-click on the pom.xml file in IntelliJ.右键单击 IntelliJ 中的 pom.xml 文件。
  2. Go to the maven option, another option will open, click on reload the project.转到maven选项,会打开另一个选项,点击reload the project。

Try this.试试这个。 it works for me这个对我有用

I had the same issue.我有同样的问题。 what i did was.我所做的是。 Select your project >right click> go to settings> plugins > search for cucumber > and then re-bundled the plugin and restart your intellij.选择您的项目>右键单击>转到设置>插件>搜索黄瓜>然后重新捆绑插件并重新启动您的intellij。 It should fix the issue.它应该解决这个问题。

如果您认为所有依赖项都在那里,则右键单击 pom.xml 并作为 maven 项目

Just run below commands只需运行以下命令

mvn idea:clean

mvn idea:idea

Nothing above worked for me unfortunately.不幸的是,以上没有对我有用。 I deleted all downloaded dependencies from .m2\\repository and did a mvn clean install to download them again.我从 .m2\\repository 中删除了所有下载的依赖项,并进行了 mvn clean install 以再次下载它们。 (Although i did not have any issues in the pom.xml at the first place) (虽然我一开始在 pom.xml 中没有任何问题)

That worked for me.那对我有用。

In my case, I've to open preferences:就我而言,我必须打开首选项:

在此处输入图片说明

And I went to Project -> Project Structure -> set my folder project in +Add Content Root然后我去Project -> Project Structure -> set my folder project in +Add Content Root

在此处输入图片说明

So now all it work fine!所以现在一切正常!

Python project蟒蛇项目

Along with setting the correct interpreter through the following settings path通过以下设置路径设置正确的解释器

File > Settings > Project > Python Interpreter

I also updated the project structure's content root to be the src directory我还将项目结构的内容根更新为src目录

File > Settings > Project > Project Structure   
- remove current content root     
- add content root to point at src

Using Kotlin/Multiplatform library使用 Kotlin/多平台库

Project structure > Modules Then remove [main] and [test] if platform are already used项目结构 > 模块 如果平台已经使用,则删除 [main] 和 [test]

示例 Example of final result最终结果示例

The same issues was on Android Studio Bumblebee in XML layout file.同样的问题出现在Android Studio Bumblebee的 XML 布局文件中。 Switching (checkout) to another branch on git and coming back to the original branch solved the issue.切换(结帐)到git上的另一个分支并返回原始分支解决了这个问题。

The answers provided here helped some, but not completely.这里提供的答案帮助了一些,但不完全。 This is because, for a multi-project solution where classes import classes from other projects, you will need to mark all relevant projects as Sources Root .这是因为,对于类从其他项目导入类的多项目解决方案,您需要将所有相关项目标记为Sources Root Marking the solution folder as Sources Root will not work.将解决方案文件夹标记为Sources Root将不起作用。

Also, I do recommend invalidating all of the caches and re-opening the solution.此外,我确实建议使所有缓存失效并重新打开解决方案。

If you are new to IntelliJ u May take some time to understand IntelliJ.如果您是 IntelliJ 的新手,您可能需要一些时间来了解 IntelliJ。 If a Code has written in Java and using cucumber framework then we have two main files -如果代码是用 Java 编写并使用 Cucumber 框架,那么我们有两个主要文件 -

  1. Feature file特征文件
  2. Step definition file步骤定义文件

Goal : what are things we have defined in feature file it must be navigate towards Step Definition File.目标:我们在特征文件中定义了什么,它必须导航到步骤定义文件。 (Ctrl +click ) Note :feature file has to contain some colourful gherkins keywords too .if it's not follow the below steps (Ctrl +click ) 注意:功能文件也必须包含一些彩色小黄瓜关键字。如果不按照以下步骤操作

Solution : go to file >>settings >> plugins - search “Cucumber for Java” Add the plugin restart IntelliJ it will work for sure .解决方案:转到文件>>设置>>插件-搜索“Cucumber for Java”添加插件重启IntelliJ它肯定会工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM