Jason Shu
Jason Shu

Reputation: 139

Scala-java.lang.ArrayIndexOutOfBoundsException: 1

I am trying to create a Row[RDD]

val RowRDD =sc.textFile("InputFile.csv").map(x=>x.split(" ")).map(p=>Row(p(1),p(2)))

InputFile.csv is

spark 5 1
hadoop 7 1
flink 10 1

However,as I am running my application,the error says

java.lang.ArrayIndexOutOfBoundsException: 1

It is obvious that the 'InputFile.csv' has 3 rows,why is there an error?

Upvotes: 0

Views: 1526

Answers (1)

Vipul Rajan
Vipul Rajan

Reputation: 642

I have attached a screenshot of my own attempt at reading your file in spark-shell; as you can very well see, there should be no problem running your particular line on that code. It very much possible that you left out some other lines in your entire code. One mistake I often make is I give a reference to a command line argument and then forget to pass any arguments on the command line. It can probably be diagnosed if you can paste the entire code. The one line given above is entirely correct. spark-shell screenshot

Upvotes: 2

Related Questions