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


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



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?




What are some SWT datagrids/tables?

1:



Exclude folders from Eclipse search
I hit the same issue last night.


How do I get the workbench window to open a modal dialog in an Eclipse based project?
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..
How to work with referenced projects in eclipse
Another thing I did that works is to go into the existing run configuration and add some junk into the "arguments" tab.


tcp/ip monitor
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.
Annoying eclipse automatically closing quotes


grails plugin for eclipse and netbeans 6.1


where are the external tools launch configurations in Eclipse [duplicate]

2:


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..


3:


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..


4:


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.


5:


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....


6:


I got the same issue.

Here is how I fixed it: Right click on your project, select "properties->Java Build Path", you can see the "Default output folder" is "your project/bin".

Change it to "your project/classes", then clean and rebuild your project.

A few complains might still show up, but it will get through - just make sure the compiled ".class" files are generated under "classes" folder . I suspect it has something to do with the underlying Java's execution engine/configuration.

Not quite sure because I'm not familier with Java..


7:


The Scala plugin is a bit unstable.

Try closing and reopening the project, that usually helps..


8:


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..


9:


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..


10:


If you use a recent version of scala (2.9.*), you should use .
object HelloWorld extends App {   println("Hello World!") } 
App, not Application.

Application was the 2.8 or 2.7 way.

Whether this is the only problem is another question..


11:


Simple Answer : if you using ( NetBeans OR Eclips ) just Restart the program else Move the Class to another class it may helps.



97 out of 100 based on 87 user ratings 937 reviews

@