Knows Not Much Knows Not Much - 1 year ago 116
Scala Question

FileTailSource throws null pointer exception

I wrote the following Alpakka code

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


I have a file called "countrycapital.csv" in the src/main/resources folder.

My objective is to build a Akka Streams Source for this file and process all the records of this file.

when I run this code. the list line throws an exception

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


I have imported the following libraries in my 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"

Answer Source

OK. I solved this myself

I didn't have a / when picking the file path.

This works without the null pointer exception

val resource = getClass.getResource("/countrycapital.csv")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download