为什么Scala说看不到org.joda.time.Period的成员? [英] Why is Scala saying it can’t see members of org.joda.time.Period?

查看:70
本文介绍了为什么Scala说看不到org.joda.time.Period的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用 Joda Time 2.0的Scala脚本.

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))

我也收到了Period.minutesPeriod.hoursPeriod.days的消息.

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

这真的很奇怪,因为我在使用其他Joda Time类没有问题,并且由于该类在Scala REPL中可以正常工作:

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))

和:

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)

这没有意义,因为joda-convert-1.2.jar在我的类路径中.

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

只是为了确保我没有对类型做一些愚蠢的事情(我是Scala的新手),所以我尝试了以下操作:val p = Period.hours(5)并遇到了同样的错误.

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.

推荐答案

按照

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

这篇关于为什么Scala说看不到org.joda.time.Period的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆