简体   繁体   中英

Scala error defining object

I've been trying to get a Scala hello world example running on Eclipse using the Scala plugin. Writing the following:

package scala_test

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

produces the following error:

<console>:1: error: eof expected but '}' found.
       }
       ^

I've tried this on both a Windows machine and a Mac (both were using Eclipse 3.7). I've tried commenting out the function definition (just leaving an empty body for the Test object) and the error still occurs. Any ideas as to what might cause this?

You need to see output in console, not in scala interpreter. Just right click on scala file and select "run as scala application".

Make sure you have added the Scala nature to the project. On some versions of the plugin, that option is only available from the contextual "Configuration" menu if the Scala perspective is active. Your project icon should have an "S" instead of a "J" in the corner if you have made this change.

Make sure its in the right package, runs for me. I'm using this plugin

http://scala-ide.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM