10

I'm completely newly at Scala.
I installed java, sbt and scala on Ubuntu 12.04:

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.

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?

  • How to solve this trouble?

Update:

  • I reinstalled newly version of IntelliJ IDEA 13 Community Edition instead 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 and scala plugins.

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. enter image description here

catch23
  • 17,519
  • 42
  • 144
  • 217

3 Answers3

7

For anyone having the same problem, start by trying the following in Idea:

File -> Invalidate Caches -> Invalidate and Restart

Jack
  • 16,506
  • 19
  • 100
  • 167
6

If your IDEA plugin doesn't see scala classes then go to File -> Project Structure and check the following:

  1. 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.

  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).

  3. Make sure scala-library.jar is on the list of dependencies of the modules using Scala. Check if paths are ok.

Piotr Kołaczkowski
  • 2,601
  • 12
  • 14
  • At project it doesn't have Scala Facet. How can I configure all this options? – catch23 Sep 23 '13 at 14:27
  • Go to Project Structure -> Facets and click the green plus icon - then select Scala. You can also add facets to the modules by right-clicking the module name in the Modules tab. – Piotr Kołaczkowski Sep 24 '13 at 07:58
  • I had to wipe out the project/ directory and then reimport to IDEA, that seemed to finally fix the issues. – user1338062 Jul 16 '14 at 14:53
  • Scala Facet is replaced with Scala SDK in IDEA 14 http://blog.jetbrains.com/scala/2014/10/30/scala-plugin-update-for-intellij-idea-14-rc-is-out/ – bachr Jul 29 '15 at 13:48
0

I'd suppose this is a problem with IDEA. You can quickly verify this if you open the same project in 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()
maksimov
  • 5,792
  • 1
  • 30
  • 38