Scala IDE错误:在'hello'类中找不到主要方法

Hem*_*apu 2 java eclipse ide scala scala-ide

我刚刚开始在Scala IDE(Eclipse)上进行scala开发.我正在尝试创建一个新项目并编写一个示例hello world程序来启动它.这是我的示例程序:

object hello {
  def main(args: String) = {
    println("Hello World!");
  }
 }
Run Code Online (Sandbox Code Playgroud)

我使用的是Java 8.我没有在程序中看到任何错误.但是,当我尝试运行该程序时,我收到如下错误:

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
Run Code Online (Sandbox Code Playgroud)

我现在一无所知.为什么要求我用Java语法创建一个main函数?为什么在代码没有问题时抛出错误(据我所知)?我尝试在现有问题上寻找答案,但没有一个是关于scala开发的.

任何帮助,将不胜感激.谢谢.

lit*_*ite 6

你的主要必须采取一串字符串.它目前需要一个字符串

来自scala的官方网站:

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

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

此外,请确保在Eclipse中使用"作为Scala应用程序运行"选项.

  • 您是否使用“作为 Scala 应用程序运行”? (2认同)