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


3 Answer(s)


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.


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/")
  
}
}

 


Hi Abhijit,

Please call me once you are availble...