Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuck at "Hello World" with IntelliJ IDEA 9.0.1 for Scala

I've been using Eclipse since 2.x and IDEs in general for over 20 years (since Turbo Pascal and Turbo C in the late '80s!).

(that preamble is supposed to imply, "I'm not an idiot" ... but doesn't sound so smart as I read it... LOL :-] )

Now I'm trying to use the Scala debugger in IntelliJ 9.0.1. I've resigned myself to an old standby, the "hello world" trick to check if the environment is setup correctly:

class hello {
  def main(a: Array[String]) = println("got args: " + a)
}

I also tried this version, just in case:

object hello extends Application {
    println("hi")
}

Alas, I'm unable to get even this simple Scala example to run. I'd like to eventually put a breakpoint in it, but for now just running it would be great. I have Java 1.6u20 and the Scala plug-in 0.3.473 (January 2010). The error below summarizes my experience:

alt text

What possibly could I be doing wrong?

Thanks

like image 634
Alex R Avatar asked Apr 19 '10 05:04

Alex R


3 Answers

From your screenshot it looks like you were using:

class hello {
  def main(a: Array[String]) = println("got args: " + a)
}

The main method has to be on an object to support a main method.

Capitalizing the object / class name is the convention but it isn't enforced.

like image 99
Don Mackenzie Avatar answered Nov 19 '22 07:11

Don Mackenzie


When you change your implementation from class to object, it works like a charm:

object Hello {
   def main(a: Array[String]) = println("got args: " + a)
}

I picked up this little, but important difference here: http://sonyarouje.com/2011/03/18/running-scala-in-intellij-idea-10/

like image 23
Lothar Krause Avatar answered Nov 19 '22 09:11

Lothar Krause


It may be a bug in the plugin. If you define you object as Hello (capitalized) then it works, at least on my machine.

like image 1
Arjan Blokzijl Avatar answered Nov 19 '22 08:11

Arjan Blokzijl