mongodb 错误:预期的类或对象定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7965028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: expected class or object definition
提问by OverStack
I have this (smart code):
我有这个(智能代码):
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.util.bson.conversions._
RegisterJodaTimeConversionHelpers() //error
object Main {
def main(args: Array[String]) {
val connection = MongoConnection()
}
}
I get an error:
我收到一个错误:
error: expected class or object definition
RegisterJodaTimeConversionHelpers()
I have to use this RegisterJodaTimeConversionHelpers()
(2.2. Briefly: Automatic Type Conversions), but there's always this error message. Any ideas?
我必须使用这个RegisterJodaTimeConversionHelpers()
(2.2。简要:自动类型转换),但总是有这个错误信息。有任何想法吗?
回答by Jean-Philippe Pellet
You have to write this line of code somewhere it can be executed. How about in your main
method instead?
您必须在可以执行的地方编写这行代码。在你的main
方法中呢?
object Main {
def main(args: Array[String]) {
RegisterJodaTimeConversionHelpers()
val connection = MongoConnection()
}
}