FileTailSource抛出空指针异常

时间:2017-10-01 00:42:25

标签: scala akka-stream alpakka

我写了以下Alpakka代码

val fs = FileSystems.getDefault
val resource = getClass.getResource("countrycapital.csv")
val source = FileTailSource.lines(Paths.get(resource.toURI), maxLineSize = 8092, pollingInterval = 10000 seconds)

我在src / main / resources文件夹中有一个名为“countrycapital.csv”的文件。

我的目标是为此文件构建一个Akka Streams Source并处理该文件的所有记录。

当我运行此代码时。列表行抛出异常

[error] (run-main-0) java.lang.NullPointerException
java.lang.NullPointerException
        at com.abhi.ElasticAkkaStreams$.delayedEndpoint$com$abhi$ElasticAkkaStreams$1(ElasticAkkaStreams.scala:37)
        at com.abhi.ElasticAkkaStreams$delayedInit$body.apply(ElasticAkkaStreams.scala:28)
        at scala.Function0.apply$mcV$sp(Function0.scala:34)
        at scala.Function0.apply$mcV$sp$(Function0.scala:34)
        at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
        at scala.App.$anonfun$main$1$adapted(App.scala:76)
        at scala.collection.immutable.List.foreach(List.scala:389)

我在build.sbt

中导入了以下库
"com.lightbend.akka" %% "akka-stream-alpakka-elasticsearch" % "0.13",
"com.lightbend.akka" %% "akka-stream-alpakka-csv" % "0.13",
"com.lightbend.akka" %% "akka-stream-alpakka-file" % "0.13"

1 个答案:

答案 0 :(得分:0)

行。我自己解决了这个问题

选择文件路径时,我没有/

这没有空指针异常

val resource = getClass.getResource("/countrycapital.csv")