Java.lang.NoSuchMethodError: main when starting HelloWorld with the Eclipse Scala plugin

I just played with Scala and installed the Eclipse plugin as described at http://www.scala-lang.org/node/94 , but after entering the Hello World example and configuring the launch configuration as described, I get the following error :

Exception in thread "main" java.lang.NoSuchMethodError: main

For reference code

package hello

object HelloWorld extends Application {
  println("Hello World!")
}

I worked a bit with the obvious solutions (adding the main method, adding a singleton object with the main method), but I'm obviously doing something wrong.

Can someone get my test case to work or indicate what I'm doing wrong?

+4
source share
11 answers

. : a) scala, ( ) .

, , - "arguments". , , ,

+4

:

package hello

class HelloWorld extends Application {
  Console.println("Hello World!")
}

class object, object, Eclipse.

+4

, , strg + s ( ). .

+2

,

package hello

object HelloWorld {
  def main(args:Array[String]) {
    println("Hello World!")
  }
}

HelloWordSrc.scala( , "Src" ), , , Eclipse . " " Eclipse, , - ,

+2

. :

  • Run- > Run Configuration
  • JavaApplication, (, hello.HelloWorld)

.

, IMHO Eclipse HelloWorld.class . , , HelloWorld $.class( ). ...

+2

. : , "properties- > Java Build Path", , " " - " / bin". " / ", . , - , ".class" "classes"

, - / Java. , familier Java.

+2

Scala . , .

+1

, . Scala Eclipse , , , , .

NetBeans. IDEA, .

+1

Netbeans ~ , . Eclipse 3.4 + Scala Plugin 2.7.5 Final . Eclipse 3.4, Scala 2.7.5, .. Scala? .. → Scala? , , .

+1

If you are using the latest version of scala (2.9. *), You should use

object HelloWorld extends App {
  println("Hello World!")
}

An application, not an application. The application was in 2.8 or 2.7 way. This is the only problem - this is another question.

0
source

The simple answer is: if you are using (NetBeans OR Eclips) just restart the program yet Move the class to another class, which may help

-3
source

All Articles