由于“找不到符号类X",因此无法在Intellij Idea中编译Java类.错误 [英] Can't compile java class in Intellij Idea due to "cannot find symbol class X" error

查看:194
本文介绍了由于“找不到符号类X",因此无法在Intellij Idea中编译Java类.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中从头开始创建了新的Java模块.在模块创建向导中选择了创建'src'文件夹".源文件夹中只有一个"com"包,其中包含两个公共类(例如A和B). A类实例化B类. IDE不会显示错误,并且当光标位于A类源中的类名称上时,按下"ctrl + B"会打开B类源.但是,当我尝试编译A类(通过上下文菜单->编译A.java类")时,会显示以下错误

I created new Java module from scratch in my project. "create 'src' folder" was selected in module creation wizard. There is single "com" package in source folder which contains two public classes (say A and B). A class instantiates B class. IDE does not show errors and B class source is opened on "ctrl+B" pressing when cursor is located on the class name inside A class source. But when I'm trying to compile A class (by context menu -> "compile A.java class") following error is shown

错误:(15,20)找不到符号类B

Error:(15, 20) cannot find symbol class B

"src"文件夹被标记为源根目录.

"src" folder is marked as source root.

它看起来像IDE错误.

It looks like IDE bug.

有人建议做文件->无效缓存"来解决同样在SO上也被问到的类似问题.我尝试过,但没有帮助.

Someone suggested to do "File->Invalidate Caches" to fix alike issue also asked on SO. I tried that and it did not help.

那可能是什么原因以及如何解决?

What possible reason of that and how it can be fixed?

-

Intellij Idea Ultimate 11.1.5.

Intellij Idea Ultimate 11.1.5.

IDE Java:1.7.0_45

IDE Java: 1.7.0_45

Project SDK:1.6.0_45

Project SDK: 1.6.0_45

推荐答案

尝试首先编译整个项目(或至少编译类B).

Try compiling the whole project (or at least class B) first.

如果仅编译 A,则无法找到类B,因为该类尚未编译(因此,不存在字节码B.class文件).

If you compile only class A, class B cannot be found because it hasn't been compiled yet (therefore, no bytecode B.class file exists).

这不是直观的,而是真实的.编译单个类时,IDEA不会自动编译依赖类.

This is not intuitive, but true. IDEA doesn't automatically compile dependant classes when you compile single class.

这篇关于由于“找不到符号类X",因此无法在Intellij Idea中编译Java类.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆