2015-02-12 63 views
0

我有一些代码行:斯卡拉 - 找到类型没有即时转换器:scala.Tuple5

import org.joda.time._ 
import org.joda.time.format._ 
val sampleDate = new DateTime(2015, 1, 1, 0, 0) 

所以我得到一个错误:

java.lang.IllegalArgumentException: No instant converter found for type: scala.Tuple5 
    at org.joda.time.convert.ConverterManager.getInstantConverter(ConverterManager.java:165) 
    at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:169) 
    at org.joda.time.DateTime.<init>(DateTime.java:168) 
    at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:19) 
    at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:24) 
    at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:26) 
    at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:28) 
    at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:30) 
    at $iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:32) 
    at $iwC$$iwC$$iwC$$iwC.<init>(<console>:34) 
    at $iwC$$iwC$$iwC.<init>(<console>:36) 
    at $iwC$$iwC.<init>(<console>:38) 
    at $iwC.<init>(<console>:40) 
    at <init>(<console>:42) 
    at .<init>(<console>:46) 
    at .<clinit>(<console>) 
    at .<init>(<console>:7) 
    at .<clinit>(<console>) 
    at $print(<console>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:852) 
    at org.apache.spark.repl.SparkIMain$Request.loadAndRun(SparkIMain.scala:1125) 
    at org.apache.spark.repl.SparkIMain.loadAndRunReq$1(SparkIMain.scala:674) 
    at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:705) 
    at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:669) 
    at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:828) 
    at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:873) 
    at org.apache.spark.repl.SparkILoop.command(SparkILoop.scala:785) 
    at org.apache.spark.repl.SparkILoop.processLine$1(SparkILoop.scala:628) 
    at org.apache.spark.repl.SparkILoop.innerLoop$1(SparkILoop.scala:636) 
    at org.apache.spark.repl.SparkILoop.loop(SparkILoop.scala:641) 
    at org.apache.spark.repl.SparkILoop$$anonfun$process$1.apply$mcZ$sp(SparkILoop.scala:968) 
    at org.apache.spark.repl.SparkILoop$$anonfun$process$1.apply(SparkILoop.scala:916) 
    at org.apache.spark.repl.SparkILoop$$anonfun$process$1.apply(SparkILoop.scala:916) 
    at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) 
    at org.apache.spark.repl.SparkILoop.process(SparkILoop.scala:916) 
    at org.apache.spark.repl.SparkILoop.process(SparkILoop.scala:1011) 
    at org.apache.spark.repl.Main$.main(Main.scala:31) 
    at org.apache.spark.repl.Main.main(Main.scala) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:358) 
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:75) 
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) 

我不知道为什么我得到这个错误,虽然这个网站: http://joda-time.sourceforge.net/api-release/org/joda/time/DateTime.html 我看到这个构造器是正确的....

DateTime 

public DateTime(int year, 
       int monthOfYear, 
       int dayOfMonth, 
       int hourOfDay, 
       int minuteOfHour) 
Constructs an instance from datetime field values using ISOChronology in the default time zone. 
Parameters: 
year - the year 
monthOfYear - the month of the year 
dayOfMonth - the day of the month 
hourOfDay - the hour of the day 
minuteOfHour - the minute of the hour 
Since: 
2.0 

谢谢!

+2

构造函数不是取6而是取5吗? – LynxZh 2015-02-12 08:33:13

+0

对不起,这是一个构造器日期时间 公开日期时间(年整型, INT monthOfYear, INT请将dayOfMonth, INT HOUROFDAY, INT minuteOfHour) – 2015-02-12 08:55:01

+0

看来,编译器治疗tuple5内的支架,你可以贴足代码段来查看是否有任何格式错误? – LynxZh 2015-02-12 09:12:27

回答

1

你的代码与2.7版本的乔达时间,但它不会与像1.6一些较旧的工作:

2.7: DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) 
1.6: DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) 

的API被改变。

我REPL:

scala> val sampleDate = new DateTime(2015, 1, 1, 0, 0) 
warning: Class org.joda.convert.FromString not found - continuing with a stub. 
warning: Class org.joda.convert.ToString not found - continuing with a stub. 
warning: Class org.joda.convert.ToString not found - continuing with a stub. 
warning: Class org.joda.convert.FromString not found - continuing with a stub. 
warning: Class org.joda.convert.ToString not found - continuing with a stub. 
sampleDate: org.joda.time.DateTime = 2015-01-01T00:00:00.000+07:00 

如果我尝试一些不恰当的参数:

scala> val sampleDate = new DateTime(2015, 1, 1, 0) 
java.lang.IllegalArgumentException: No instant converter found for type: scala.Tuple4 

附:乔达时间罐被放置在lib_managed\jars文件夹内。所以你可以检查你的版本。我分别使用spark-1.2.0和joda-time-2.1.0,因此您应该至少使用Spark的1.2.0版本update来使用新的API。