Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

eclipse

scala

I've just been playing with Scala, and installed the Eclipse plugin as described at http://www.scala-lang.org/node/94, but after entering the "Hello World" test example and setting up the run configuration as described, I get the following error

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

For reference the code is

package hello

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

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

Can anyone get their test example to work, or point out what I am doing wrong?

like image 356
Matt Sheppard Avatar asked Dec 06 '22 05:12

Matt Sheppard


2 Answers

I hit the same issue last night. I fixed it by a) removing any existing scala run configurations and then by (I'm not kidding) adding a linebreak before the first curly brace.

Another thing I did that works is to go into the existing run configuration and add some junk into the "arguments" tab. I'm ignoring the arguments anyway, so it didn't affect the output of the program, but it got the plugin to find main again

like image 180
marc esher Avatar answered Feb 15 '23 10:02

marc esher


I also hit this error with the below code:

package hello

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

The error was using class instead of object, when I switched to object it ran fine in Eclipse.

like image 26
brent.payne Avatar answered Feb 15 '23 09:02

brent.payne