title: NoSuchElementException: next on empty iterator in MapPartitionsToPair-Spark
body: <p>I'm trying to do a <code>MapPartitionsToPair</code> in Spark Streaming, but it always returns the error: NoSuchElementException: next on empty iterator.</p>
  
  <p>Here is my code:</p>
  
  <pre><code> JavaPairDStream&lt;String,String&gt; streamGiveKey=   streamData1.mapPartitionsToPair(new PairFlatMapFunction&lt;Iterator&lt;String&gt;, String, String&gt;() {
        @Override
        public Iterable&lt;Tuple2&lt;String, String&gt;&gt; call(Iterator&lt;String&gt; stringIterator) throws Exception {
  
              ArrayList&lt;Tuple2&lt;String,String&gt;&gt;arrayOfPartitionsWithKeys= new ArrayList&lt;Tuple2&lt;String, String&gt;&gt;();
  
               while (stringIterator.hasNext()){
                   if(stringIterator.next()==null){
                       return null;
                   }
  
                   JsonMessage retMap = new Gson().fromJson(stringIterator.next(),JsonMessage.class);
                   String key= retMap.getSid();
                  Tuple2&lt;String,String&gt; keyValue= new Tuple2&lt;String,String&gt;(key,stringIterator.next());
                   arrayOfPartitionsWithKeys.add(keyValue);
  
               }
  
  
   return  arrayOfPartitionsWithKeys;
           }
      });
  </code></pre>
  
  <p>Can anyone tell me what the problem might be?
  Thank you so much.</p>