title: NULL Pointer Exception, while creating DF inside foreach()
body: <p>I have to read certain files from S3, so I created a CSV containing path of those files on S3. I am reading created CSV file using below code:</p>
  
  <pre><code>val listofFilesRDD = sparkSession.read.textFile("s3://"+ file)
  </code></pre>
  
  <p>This is working fine.
  Then I am trying to read each of those paths and create dataframe like:</p>
  
  <pre><code>listofFilesRDD.foreach(iter =&gt; {
    val pathDF = sparkSession.read
      .schema(testSchema)
      .option("headers", true)
      .csv("s3://"+iter)
  
    pathDF.printSchema()
  })
  </code></pre>
  
  <p>but, the above code gives NullPointerException.</p>
  
  <p>So, How can I fix the above code?</p>