title: spark scala throws java.util.NoSuchElementException: key not found: 0 exception
body: <p>I have a piece of spark scala code like this:</p>
  
  <pre><code>val conf = new SparkConf().setAppName("MatrixInversion").setMaster("local")
  
  val sc = new SparkContext(conf)
  
    def main (args: Array[String]) {
  
      var array:Array[Array[Double]]=new Array(2)
      for(i&lt;- 0 until 2)
        array(i)=new Array(2)
  
      array(0)(0)=1
      array(0)(1)=2
      array(1)(0)=3
      array(1)(1)=4
  
      sc.makeRDD(array).cache()
  
      //val matrixA3=sc.textFile("A3")
      testCache()
  
      sc.stop()
  
    }
  
    def testCache():Unit={
  
      val rdds=sc.getPersistentRDDs
      val cacheArray=rdds(0).asInstanceOf[RDD[Array[Double]]]
      println("print cachaArray")
      cacheArray.collect()
      val cacheLength=cacheArray.collect().length
      println("length"+cacheLength)
    }
  </code></pre>
  
  <p>and now it will be ok. But when I uncomment this line: <code>val matrixA3=sc.textFile("A3")</code></p>
  
  <p>It has something wrong like this:</p>
  
  <pre><code>Exception in thread "main" java.util.NoSuchElementException: key not found: 0
      at scala.collection.MapLike$class.default(MapLike.scala:228)
      at scala.collection.AbstractMap.default(Map.scala:58)
      at scala.collection.MapLike$class.apply(MapLike.scala:141)
      at scala.collection.AbstractMap.apply(Map.scala:58)
      at com.scala.inversion.test$.testCache(test.scala:117)
  </code></pre>
  
  <p>Why?</p>