title: JavaPairRDD to DataFrame in Apache Spark with java
body: <p>I have some document file, I try to read data and then zip with index using zipWithIndex() function follow:</p>
  
  <pre><code>    JavaRDD&lt;String&gt; rawTextRDD = sc.textFile("demo.txt");
      JavaPairRDD&lt;String, Long&gt; zipIndex = rawTextRDD.zipWithIndex();
  </code></pre>
  
  <p>After that value of zipIndex is a JavaPairRDD containing key-value pair, look like ["This is the beautiful picture", 0], ["This is another picture", 1].</p>
  
  <p>But now, I want to convert zipIndex into DataFrame using:</p>
  
  <pre><code>DataFrame docDF = sqlContext.createDataFrame(zipIndex, TextId.class);
  </code></pre>
  
  <p>function createDataFrame does not accept parameter zipIndex (TextId is a class with 2 property: String text and int docId).</p>
  
  <p>I also have a code in Scala, and it run very well. Please refer to this:</p>
  
  <pre><code>val rawTextRDD = sc.textFile("demo.txt")
  val docDF = rawTextRDD.zipWithIndex.toDF("text", "docId")
  </code></pre>
  
  <p>If there is any solution. Please help me to resolve. Thanks</p>