Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala IDE Error: Main method not found in class 'hello'

I am just beginning with my scala development on the Scala IDE(Eclipse). I am trying to create a new project and write a sample hello world program to kick things off. This is my sample program:

object hello {
  def main(args: String) = {
    println("Hello World!");
  }
 }

I am using Java 8. I don't see any errors in the program. However, when I try to run the program, I get an error like this:

Error: Main method not found in class hello, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

I am now clueless. Why is it asking me to create a main function with Java syntax? And why is it throwing an error when there are no problems with the code(As far as I know)? I tried searching for answers on the existing questions but none of them are about scala development.

Any help would be appreciated. Thank you.

like image 333
Hemanth Annavarapu Avatar asked Dec 19 '22 07:12

Hemanth Annavarapu


1 Answers

Your main must take an array of string. It currently takes a single string

From scala's official website :

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}

https://www.scala-lang.org/documentation/getting-started.html

Also, make sure you are using the "run as Scala application" option in Eclipse.

like image 159
litelite Avatar answered Dec 24 '22 20:12

litelite