tags:

views:

3512

answers:

10

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?

+1  A: 

The Scala plugin is a bit unstable. Try closing and reopening the project, that usually helps.

starblue
Project->Clean should also do the trick without needing a restart.
Jon McAuliffe
+1  A: 

Unfortunately, you did nothing wrong. Scala's Eclipse plugin has seen better days, but it has been rewritten to take advantage of some recent features enabling better integration, and the present version is buggy.

Right now, I recommend NetBeans. Or IDEA, if you've got the money.

Daniel
You can always use the IDEA EAP if you're not looking to spend money on something you're experimenting with.
Geoffrey Wiseman
+1  A: 

Netbeans works ~ok but also has problems. Right now I have a good Eclipse 3.4 + Scala Plugin 2.7.5 Final working very well. I suggest you do a clean install of Eclipse 3.4, Scala 2.7.5, clean your project etc. Did you create the project with the Scala project creator? i.e. Create new project -> Scala project? All this is of course if nothing else is working for you.

Antony Stubbs
+2  A: 

I solve the problem by cleaning the project, then going to the class with the main method and building it with strg+s (auto build on). Works like a charm.

Alexander Stolz
just to point out I had the same trouble with Netbeans' compile on save feature on.turning it off(project->properties->Compiling) and manually compiling worked.
Adil Butt
+1  A: 

It is a little bit ugly, but you can place

package hello

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

inside a File HelloWordSrc.scala (or whatever you like instead of the trailing "Src"), maybe clean the project once, and then Eclipse should run it. The "extends Application" did never work for me inside Eclipse, but the plugin looks for a main method inside the code, which for some reason cannot have the same name as designated by the file's name

cheers

+2  A: 

Had exactly the same problem. The solution for me was this:

  • Go to Run->Run Configuration
  • Create new JavaApplication configuration where manually specify the full class name (e.g. hello.HelloWorld)
  • Apply and run

That should be it.

EDIT

As to the cause of the problem, IMHO Eclipse is looking for file HelloWorld.class to be executed. However, what it should be looking for is HelloWorld$.class (or the other way around). But this assumption could be wrong...

01es
+2  A: 

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

marc esher
+1  A: 

for me neither cleaning nor closing the project worked. first of all my class was not in the package "hello" - creating this package and moving the class to the package "hello" solved my problem

(i'm using eclipse 3.5 and scala 2.7.7.final)

d.b.
A: 

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.

A: 

I also have the same error..can anybody help ?

Rani