6

I'm trying to run a simple Scala snippet,

package example

class HelloWorld extends App {
  println("Hello world")
}

in the IntelliJ IDE with Scala installed. However, the "Run" button appears to be grayed out, and I also don't see it in the context menu (not shown in the screen grab below).

enter image description here

In accordance with the answer of Unable to run Java code with Intellij IDEA, the code is in the src folder which is marked blue. (I've also tried marking it as a 'tests' folder but to no avail). What am I missing?

Kurt Peek
  • 52,165
  • 91
  • 301
  • 526

1 Answers1

17

HelloWorld should be object, not class:

package example

object HelloWorld extends App {
  println("Hello world")
}

For more info about singleton objects, you can see this chapter of "Programming in Scala" book and this question.

TeWu
  • 5,928
  • 2
  • 22
  • 36