Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.refArrayOps(

Manoj4068 picture Manoj4068 · Apr 3, 2017 · Viewed 10.1k times · Source

I am new to scala and getting below error for code in INTELLJ can any one please help to resolve it

     import org.apache.spark.{SparkContext, SparkConf}
     object wordcount {
     def main(args: Array[String])
      {
      val conf = new SparkConf()
      .setMaster("local[*]")
      .setAppName("TestSpark")
      .set("spark.executor.memory","2g")

       val sc = new SparkContext(conf)
       val a  = sc.parallelize(Seq("This is the firstline", "This is the  
       second line", "This is the third line"))              
       val count = a.flatMap(x => x.split(" "))
       val counts = count.map(word => (word,1)).reduceByKey((x,y) => x+y)
        counts.foreach(println)

       }

       }

I am getting below error :

      Exception in thread "main" java.lang.NoSuchMethodError:    
     scala.Predef$.refArrayOps([Ljava/lang/Object;)
      Lscala/collection/mutable/ArrayOps;
      at org.apache.spark.util.Utils$.getCallSite(Utils.scala:1342)
     at org.apache.spark.SparkContext.<init>(SparkContext.scala:81)
     at wordcount$.main(wordcount.scala:12)
     at wordcount.main(wordcount.scala)
     Using Spark's default log4j profile: org/apache/spark/log4j-    

Below is my built SBT

      name := "scalaprograms"

      version := "1.0"

       scalaVersion := "2.12.1"

      libraryDependencies += "org.apache.spark" % "spark-core_2.11" %

Answer

Raphael Roth picture Raphael Roth · Apr 3, 2017

You should use Scala 2.11 in order to work withspark-core_2.11. I.e. use :

scalaVersion := "2.11.8"

AFAIk Spark does not work yet with Scala 2.12