Java 在 Scala 项目中,编译器错误 - 无法解析符号列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18960227/
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
at scala project, compiler error - Cannot resolve symbol List?
提问by nazar_art
I'm completely newly at Scala.
I installed java, sbt and scala on Ubuntu 12.04:
我是 Scala 的新手。
我在 Ubuntu 12.04 上安装了 java、sbt 和 scala:
nazar_art@nazar-desctop:~$ sbt sbt-version
[warn] Alternative project directory .sbt (/home/nazar_art/.sbt) has been deprecated since sbt 0.12.0.
[warn] Please use the standard location: /home/nazar_art/project
[info] Loading project definition from /home/nazar_art/.sbt
[info] Set current project to default-5b9232 (in build file:/home/nazar_art/)
[info] 0.12.4
nazar_art@nazar-desctop:~$ scala -version
Scala code runner version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL
nazar_art@nazar-desctop:~$ java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
I installed scala and sbt plugins to Idea.
我为 Idea 安装了 scala 和 sbt 插件。
And when I tried irst example project I see next error:
当我尝试第一个示例项目时,我看到下一个错误:
Cannot resolve symbol List, after next lines:
无法解析符号列表,在下一行之后:
package example
import common._
object Lists {
def sum(xs: List[Int]): Int = { // <== here underline for List
if (xs.isEmpty) 0
else xs.head + sumList(xs.tail)
}
}
I couldn't figure out what exactly is wrong?
IDEA suggest me importing java.util.List
- but this class doesn't have any isEmpthy()
method.
Any suggestion?
我无法弄清楚到底出了什么问题?IDEA 建议我导入java.util.List
- 但这个类没有任何isEmpthy()
方法。
有什么建议吗?
- How to solve this trouble?
- 如何解决这个烦恼?
Update:
更新:
- I reinstalled newly version of IntelliJ IDEA 13 Community
Editioninstead of # 12. Untared in
/usr/local/Idea
. - Removed sbt -
sudo apt-get purge sbt
. And reinstall accord this script. I went to
/MyProjectDirectory/project/
and created 'plugin.sbt' with content:addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")
After this I type from my project directory
sbt gen-idea
. It rebuild project for Idea.- And opened this project with idea greeting window (Open Paroject). Of course,
installed
sbt
andscala
plugins.
- 我重新安装了新版本的IntelliJ IDEA 13 社区版而不是 #12。在
/usr/local/Idea
. - 删除了 sbt -
sudo apt-get purge sbt
。并根据此脚本重新安装。 我去
/MyProjectDirectory/project/
创建了带有内容的“plugin.sbt”:addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")
在此之后,我从我的项目目录中键入
sbt gen-idea
。它为 Idea 重建项目。- 并用想法问候窗口(Open Paroject)打开这个项目。当然,安装
sbt
和scala
插件。
It should be enough but it shown again:
它应该足够了,但它再次显示:
Cannot resolve symbol List
and suggesting import import scala.collection.immutable.List
. But this isn't helpful. It keep being underlined with red line.
并建议导入import scala.collection.immutable.List
。但这没有帮助。它一直用红线下划线。
采纳答案by Piotr Ko?aczkowski
If your IDEA plugin doesn't see scala classes then go to File -> Project Structure and check the following:
如果您的 IDEA 插件没有看到 scala 类,请转到 File -> Project Structure 并检查以下内容:
Make sure the Scala Facet is added to your application. Go to the Facets tab and check if Scala facet is listed there. If not, you need to add and configure it. Then make sure that Scala Facet is listed under all the modules that need Scala.
Make sure the Scala Facet uses the right version of your scala library (Idea will mark it with red, if it cannot be found).
Make sure scala-library.jar is on the list of dependencies of the modules using Scala. Check if paths are ok.
确保将 Scala Facet 添加到您的应用程序中。转到 Facets 选项卡并检查那里是否列出了 Scala facet。如果没有,则需要添加和配置它。然后确保 Scala Facet 列在所有需要 Scala 的模块下。
确保 Scala Facet 使用正确版本的 Scala 库(如果找不到,Idea 会将其标记为红色)。
确保 scala-library.jar 在使用 Scala 的模块的依赖项列表中。检查路径是否正常。
回答by maksimov
I'd suppose this is a problem with IDEA. You can quickly verify this if you open the same project in Scala IDE.
我想这是IDEA的一个问题。如果您在Scala IDE 中打开同一个项目,您可以快速验证这一点。
Also you can try in command line:
您也可以在命令行中尝试:
[m:~/Scala/Hello]$ scala
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
scala> var l = List()
l: List[Nothing] = List()
回答by Hyman
For anyone having the same problem, start by trying the following in Idea:
对于遇到相同问题的任何人,请先在 Idea 中尝试以下操作:
File -> Invalidate Caches -> Invalidate and Restart
File -> Invalidate Caches -> Invalidate and Restart