简体   繁体   English

在 Scala 项目中,编译器错误 - 无法解析符号列表?

[英]at scala project, compiler error - Cannot resolve symbol List?

I'm completely newly at Scala.我是 Scala 的新手。
I installed java, sbt and scala on Ubuntu 12.04:我在 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. IDEA 建议我导入java.util.List - 但这个类没有任何isEmpthy()方法。
Any suggestion?有什么建议吗?

  • How to solve this trouble?如何解决这个烦恼?

Update:更新:

  • I reinstalled newly version of IntelliJ IDEA 13 Community Edition instead of # 12. Untared in /usr/local/Idea .我重新安装了新版本的IntelliJ IDEA 13 Community Edition而不是 #12。在/usr/local/Idea解压。
  • Removed sbt - sudo apt-get purge sbt .删除了 sbt - sudo apt-get purge sbt And reinstall accord this script .并根据此脚本重新安装。
  • I went to /MyProjectDirectory/project/ and created 'plugin.sbt' with content:我去了/MyProjectDirectory/project/并用内容创建了“plugin.sbt”:

    addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")

  • After this I type from my project directory sbt gen-idea .在此之后,我从我的项目目录中sbt gen-idea It rebuild project for Idea.它为 Idea 重建项目。

  • And opened this project with idea greeting window (Open Paroject).并用创意问候窗口(Open Paroject)打开这个项目。 Of course, installed sbt and scala plugins.当然,安装了sbtscala插件。

It should be enough but it shown again:它应该足够了,但它再次显示:

Cannot resolve symbol List

and suggesting import import scala.collection.immutable.List .并建议 import import scala.collection.immutable.List But this isn't helpful.但这没有帮助。 It keep being underlined with red line.它一直用红线下划线。在此处输入图片说明

If your IDEA plugin doesn't see scala classes then go to File -> Project Structure and check the following:如果您的 IDEA 插件没有看到 scala 类,请转到 File -> Project Structure 并检查以下内容:

  1. Make sure the Scala Facet is added to your application.确保将 Scala Facet 添加到您的应用程序中。 Go to the Facets tab and check if Scala facet is listed there.转到 Facets 选项卡并检查那里是否列出了 Scala facet。 If not, you need to add and configure it.如果没有,则需要添加和配置它。 Then make sure that Scala Facet is listed under all the modules that need Scala.然后确保 Scala Facet 列在所有需要 Scala 的模块下。

  2. Make sure the Scala Facet uses the right version of your scala library (Idea will mark it with red, if it cannot be found).确保 Scala Facet 使用正确版本的 Scala 库(如果找不到,Idea 会将其标记为红色)。

  3. Make sure scala-library.jar is on the list of dependencies of the modules using Scala.确保 scala-library.jar 在使用 Scala 的模块的依赖项列表中。 Check if paths are ok.检查路径是否正常。

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

I'd suppose this is a problem with IDEA.我想这是IDEA的一个问题。 You can quickly verify this if you open the same project in Scala IDE .如果您在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()

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

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