Error:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0



0

Hi,

I am facing below issue while running simple Spark word count program

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0


3 Answer(s)


0

Hi Ramesh,

Could you please share the code with us. You are using the array elements which is not present.

For example, if your array contains 10 elements and if you try to read the element with index 10 or more than. It will generate the same exception.

Hope this helps.

Thanks.


0

Hi Abhijit,

Here i am sharing code for refernce.

package test.com.spark05
import org.apache.spark._
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf

object word1 {
  def main(args: Array[String]) {
    //Spark configuration
   val conf=new SparkConf()
            .setAppName("wordCount")
            .setMaster("local")
   //spark context
   val sc = new SparkContext(conf)
 /*  val file= sc.textFile(args(0))
   val words=file.flatMap(line=> line.split(" "))
   val wordsKV=words.map(word=>(word,1))
   val wordCount=wordsKV.reduceByKey(_+_)*/
   
   val fileRdd=sc.textFile("F:/Spark/scala.txt").flatMap(line=>line.split(" "))
                                                      .map(word=>(word,1))
                                                      .reduceByKey(_+_)
                                                       .saveAsTextFile("E:/New/")
  
}
}

 


0

Hi Abhijit,

Please call me once you are availble...