Java 为什么我收到“无法解析符号”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21339934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why am I getting "Cannot resolve symbol"?
提问by ddavison
I've imported this project before, with no difficulty before. I'm not sure what has changed.
我之前导入过这个项目,之前没有任何困难。我不确定发生了什么变化。
I click Import Project
and selected getting-started-with-selenium
(http://github.com/ddavison/getting-started-with-selenium) which is a Maven project, and an old Eclipse project. I clicked the directory, then in the "Select libraries" or whatever, i selected Maven
.
我单击Import Project
并选择getting-started-with-selenium
( http://github.com/ddavison/getting-started-with-selenium),这是一个 Maven 项目和一个旧的 Eclipse 项目。我点击了目录,然后在“选择库”或其他任何地方,我选择了Maven
.
I've changed my build path to match correctly...
我已经改变了我的构建路径以正确匹配......
src/
main/
java/ <-- source folder.
tests/
java/ <-- tests folder.
But yet, I get "Cannot resolve symbol 'After'"
Even though in the maven libraries, I see it clearly.
但是,我得到了"Cannot resolve symbol 'After'"
即使在 Maven 库中,我也清楚地看到了。
Let me know if there is any additional information needed.
如果需要任何其他信息,请告诉我。
采纳答案by Mark Peters
Make sure that if JUnit is declared as <scope>test</scope>
, that your test class is in src/test
, otherwise it won't be able to see the dependency.
确保如果 JUnit 声明为<scope>test</scope>
,则您的测试类在 中src/test
,否则它将无法看到依赖项。
回答by Makoto
Make sure that you can compile the project through Maven (that is, via command line) through mvn clean compile
.
确保您可以通过 Maven(即通过命令行)通过mvn clean compile
.
If that generates errors, be sure that you have the junit dependency properly scoped in the POM.
如果这会产生错误,请确保在 POM 中正确设置了 junit 依赖项。
If that doesn't generate errors, then it's IntelliJ that doesn't know where the new libraries are.
如果这不会产生错误,则是 IntelliJ 不知道新库在哪里。
To fix that, simply go to the Maven Projects tab in the main window, and hit the "Generate Sources and Update Folders for All Projects" button. Then, hit "Reimport All Maven Projects", which is next to the previous button.
要解决这个问题,只需转到主窗口中的 Maven 项目选项卡,然后点击“为所有项目生成源和更新文件夹”按钮。然后,点击上一个按钮旁边的“重新导入所有 Maven 项目”。
回答by user1522377
I have a project in Eclipse.
我在 Eclipse 中有一个项目。
- Click right mouse button on your project root -> Context menu
- Select this menu : Maven > Update project
- 在项目根目录上单击鼠标右键 -> 上下文菜单
- 选择此菜单:Maven > 更新项目