问题
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