title: java.lang.NullPointerException in my Spark Streaming Application
body: <p>My spark application need to process a data stream.
  To do that i use two sparks modules: the streaming module and the sql module.
  In particular i need to use the sql module because i have to query, for every record recived from the stream, an hive table in the local metastore.</p>
  
  <p>The MAIN PROBLEM is the following: After the start of the stream processing (via the method start of the streaming context) i am unable to use the sqlContext. When i try to use the sqlContext during the stream processing spark raise the following error:</p>
  
  <pre><code>15/06/22 12:41:15 ERROR Executor: Exception in task 0.0 in stage 2.0 (TID 2)
  java.lang.NullPointerException
      at org.apache.spark.sql.SQLContext.currentSession(SQLContext.scala:897)
      at org.apache.spark.sql.SQLContext.conf(SQLContext.scala:73)
      at org.apache.spark.sql.SQLContext.getConf(SQLContext.scala:106)
      at org.apache.spark.sql.hive.HiveContext.hiveMetastoreVersion(HiveContext.scala:114)
      at org.apache.spark.sql.hive.HiveContext.metadataHive$lzycompute(HiveContext.scala:176)
      at org.apache.spark.sql.hive.HiveContext.metadataHive(HiveContext.scala:175)
      at org.apache.spark.sql.hive.HiveContext$$anon$2.&lt;init&gt;(HiveContext.scala:370)
      at org.apache.spark.sql.hive.HiveContext.catalog$lzycompute(HiveContext.scala:370)
      at org.apache.spark.sql.hive.HiveContext.catalog(HiveContext.scala:369)
      at org.apache.spark.sql.hive.HiveContext.catalog(HiveContext.scala:71)
      at org.apache.spark.sql.SQLContext.tableNames(SQLContext.scala:787)
      at Test$.getDangerousness(test.scala:84)
      at Test$$anonfun$5.apply(test.scala:126)
      at Test$$anonfun$5.apply(test.scala:126)
      at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
      at scala.collection.Iterator$$anon$10.next(Iterator.scala:312)
      at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
      at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
      at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
      at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
      at scala.collection.AbstractIterator.to(Iterator.scala:1157)
      at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
      at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
      at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
      at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
      at org.apache.spark.rdd.RDD$$anonfun$take$1$$anonfun$28.apply(RDD.scala:1272)
      at org.apache.spark.rdd.RDD$$anonfun$take$1$$anonfun$28.apply(RDD.scala:1272)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:63)
      at org.apache.spark.scheduler.Task.run(Task.scala:70)
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  15/06/22 12:41:15 WARN TaskSetManager: Lost task 0.0 in stage 2.0 (TID 2, localhost): java.lang.NullPointerException
      at org.apache.spark.sql.SQLContext.currentSession(SQLContext.scala:897)
      at org.apache.spark.sql.SQLContext.conf(SQLContext.scala:73)
      at org.apache.spark.sql.SQLContext.getConf(SQLContext.scala:106)
      at org.apache.spark.sql.hive.HiveContext.hiveMetastoreVersion(HiveContext.scala:114)
      at org.apache.spark.sql.hive.HiveContext.metadataHive$lzycompute(HiveContext.scala:176)
      at org.apache.spark.sql.hive.HiveContext.metadataHive(HiveContext.scala:175)
      at org.apache.spark.sql.hive.HiveContext$$anon$2.&lt;init&gt;(HiveContext.scala:370)
      at org.apache.spark.sql.hive.HiveContext.catalog$lzycompute(HiveContext.scala:370)
      at org.apache.spark.sql.hive.HiveContext.catalog(HiveContext.scala:369)
      at org.apache.spark.sql.hive.HiveContext.catalog(HiveContext.scala:71)
      at org.apache.spark.sql.SQLContext.tableNames(SQLContext.scala:787)
      at Test$.getDangerousness(test.scala:84)
      at Test$$anonfun$5.apply(test.scala:126)
      at Test$$anonfun$5.apply(test.scala:126)
      at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
      at scala.collection.Iterator$$anon$10.next(Iterator.scala:312)
      at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
      at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
      at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
      at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
      at scala.collection.AbstractIterator.to(Iterator.scala:1157)
      at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
      at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
      at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
      at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
      at org.apache.spark.rdd.RDD$$anonfun$take$1$$anonfun$28.apply(RDD.scala:1272)
      at org.apache.spark.rdd.RDD$$anonfun$take$1$$anonfun$28.apply(RDD.scala:1272)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:63)
      at org.apache.spark.scheduler.Task.run(Task.scala:70)
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>`</p>
  
  <p>where Test is the main class and getDangerousness is the method that try to use the sqlContext.</p>
  
  <p>Thanks in advance.</p>