检查播放当前模式会发生错误 [英] Checking a play current mode makes an error occur
本文介绍了检查播放当前模式会发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Play应用程序中获取当前模式:
I'm trying to get the current mode in Play application:
object Global extends GlobalSettings {
val myVal = {
val (a, b, c) = Play.current.mode match {
case Mode.Dev | Mode.Test => ("a", "b", "c")
case Mode.Prod => ("d", "e", "f")
}
new myClass(a, b, c)
}
}
该错误发生在运行时说Cannot initialize the custom Global object (%s) (perhaps it's a wrong reference?)
,通过stacktrace我可以看到它发生在val MyVal = {...
The error occurs in runtime saying Cannot initialize the custom Global object (%s) (perhaps it's a wrong reference?)
and by stacktrace I can see it happens at val MyVal = {...
当我从Global
中删除该字段时,错误将消失.
When I remove that field from Global
then the error will disappear.
这是怎么了?
推荐答案
我几乎不相信您想要做onStart
或onStop
或其他活动,但不仅仅是因为;)
I hardly believe that you want to do something onStart
or onStop
, or maybe or some other event, but not just because ;)
object Global extends GlobalSettings {
override def onStart(app: Application) {
// put your code here....
}
}
这篇关于检查播放当前模式会发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文