Why is Scala saying it can’t see members of org.joda.time.Period?

元气小坏坏 提交于 2019-12-10 15:53:49

问题


I’m writing a Scala script which uses Joda Time 2.0.

When I try to run my script, I get errors like this:

error: value weeks is not a member of object org.joda.time.Period
        case "w" => Some(Period.weeks(windowSpecNum))

I’m also getting the message for Period.minutes, Period.hours, and Period.days.

This is really strange because I’m having no problem using other Joda Time classes, and because this class works fine in the Scala REPL:

scala> Period.minutes(5)
res0: org.joda.time.Period = PT5M

I tried a few workarounds:

error: org.joda.time.Period does not have a constructor
        case "m" => Some(new Period().withMinutes(windowSpecNum))

and:

case "m" => Some(Minutes.minutes(windowSpecNum))
error: error while loading Minutes, Missing dependency 'class org.joda.convert.FromString', required by lib/joda-time-2.0.jar(org/joda/time/Minutes.class)

which makes no sense, as joda-convert-1.2.jar is in my classpath.

Just to make sure I wasn’t doing something dumb with types (I’m new to Scala) I tried this: val p = Period.hours(5) and got the same kind of error.


回答1:


As per this thread, the problem may have been that your classpath did not include a Joda Time dependency named Joda Convert.



来源:https://stackoverflow.com/questions/8619348/why-is-scala-saying-it-can-t-see-members-of-org-joda-time-period

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!