Exception in thread "main" java.time.format.DateTimeParseException: Text '31-Dec-13' could not be pa

完整报错如下:

------------------------------看下lines-----------------------------------
lines=Stream(Date,Open,High,Low,Close,Volume, ?)
lines=Stream(31-Dec-13,114.61,117.13,114.46,116.12,12838233, ?)
Exception in thread "main" java.time.format.DateTimeParseException: Text '31-Dec-13' could not be parsed at index 3
	at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	at java.time.LocalDate.parse(LocalDate.java:400)
	at RunRisk$$anonfun$readGoogleHistory$1.apply(RunRisk.scala:82)
	at RunRisk$$anonfun$readGoogleHistory$1.apply(RunRisk.scala:80)
	at scala.collection.immutable.Stream.map(Stream.scala:418)
	at RunRisk.readGoogleHistory(RunRisk.scala:80)
	at RunRisk$$anonfun$11.apply(RunRisk.scala:160)
	at RunRisk$$anonfun$11.apply(RunRisk.scala:160)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
	at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:186)
	at RunRisk.readStocksAndFactors(RunRisk.scala:160)
	at RunRisk$.main(RunRisk.scala:36)
	at RunRisk.main(RunRisk.scala)

Process finished with exit code 1

这里的index就是31-Dec-13里面的-

当然了,理解index对于解决问题毫无帮助。

 

耗时很久,巨恶心,解决方案如下:

import java.time.format.DateTimeFormatter
import java.util.Locale
val formatter = DateTimeFormatter.ofPattern("d-MMM-yy",Locale.ENGLISH)

环境为:

ubuntu18.10,amd64

jdk1.8.0_201

Intellij2018

 

你可能感兴趣的:(Java编程,Scala与Spark)