title: Spark NotSerializableException
body: <p>In my Spark code, I am attempting to create an IndexedRowMatrix from a csv file. However, I get the following error:</p>
  
  <pre><code>Exception in thread "main" org.apache.spark.SparkException: Task not serializable
  ...
  Caused by: java.io.NotSerializableException: org.apache.spark.api.java.JavaSparkContext
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>sc = new JavaSparkContext("local", "App",
                "/srv/spark", new String[]{"target/App.jar"});
  
  JavaRDD&lt;String&gt; csv = sc.textFile("data/matrix.csv").cache();
  
  
  JavaRDD&lt;IndexedRow&gt; entries = csv.zipWithIndex().map(
                new  Function&lt;scala.Tuple2&lt;String, Long&gt;, IndexedRow&gt;() {
                  /**
                   * 
                  **/ 
                  private static final long serialVersionUID = 4795273163954440089L;
  
                  @Override
                  public IndexedRow call(Tuple2&lt;String, Long&gt; tuple)
                          throws Exception {
                      String line = tuple._1;
                      long index = tuple._2;
                      String[] strings = line.split(",");
                      double[] doubles = new double[strings.length];
                       for (int i = 0; i &lt; strings.length; i++) {
                           doubles[i] = Double.parseDouble(strings[i]);
                       }
                       Vector v = new DenseVector(doubles);
                       return new IndexedRow(index, v);
                  }
              });
  </code></pre>