title: Error in writing to .doc file by Apache POI
body: <p>I'm writing a app to display and edit file .doc  I'm using POI with HWPF. Now I can read text from file and write to file .doc too. But my reader only read default file .doc which is created by msoffice, It can't read the file created by my writer also msoffice can read this and all content was displayed right. It always show error:</p>
  
  <pre><code>Exception in thread "main" java.lang.RuntimeException:java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  at org.apache.poi.hwpf.extractor.WordExtractor.getText(WordExtractor.java:322)
  at ReadPOI.main(ReadPOI.java:18)
  Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  at java.util.ArrayList.RangeCheck(ArrayList.java:547)
  at java.util.ArrayList.get(ArrayList.java:322)
  at org.apache.poi.hwpf.usermodel.Range.binarySearchStart(Range.java:1016)
  at org.apache.poi.hwpf.usermodel.Range.findRange(Range.java:1095)
  at org.apache.poi.hwpf.usermodel.Range.initParagraphs(Range.java:982)
  at org.apache.poi.hwpf.usermodel.Range.numParagraphs(Range.java:311)
  at org.apache.poi.hwpf.converter.AbstractWordConverter.processParagraphes(AbstractWordConverter.java:1058)
  at org.apache.poi.hwpf.converter.WordToTextConverter.processSection(WordToTextConverter.java:435)
  at org.apache.poi.hwpf.converter.AbstractWordConverter.processSingleSection(AbstractWordConverter.java:1126)
  at org.apache.poi.hwpf.converter.AbstractWordConverter.processDocument(AbstractWordConverter.java:722)
  at org.apache.poi.hwpf.extractor.WordExtractor.getText(WordExtractor.java:304)
  ... 1 more
  </code></pre>
  
  <p>Are there any different between file created by msoffice and file created by my writer, and how to fix it. Please help me. There are my demo code in Java. Thank you</p>
  
  <p>My reader:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  
  import org.apache.poi.hwpf.HWPFDocument;
  import org.apache.poi.hwpf.extractor.WordExtractor;
  import org.apache.poi.hwpf.usermodel.Range;
  
  
  public class ReadPOI 
  {
  public static void main(String args[]) throws Exception
  {
      File file = new File("Test.doc");
      FileInputStream fin = new FileInputStream(file);
      HWPFDocument doc = new HWPFDocument(fin);
      Range range = doc.getRange();
      WordExtractor extractor = new WordExtractor(doc);
      System.out.println("starting\n" + extractor.getText() + "end\n");
  
      fin.close();
  }
  }
  </code></pre>
  
  <p>My Writer:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  
  import org.apache.poi.hwpf.HWPFDocument;
  
  public class WritePOI
  {
  public static void main(String args[]) throws Exception
  {
      File file = new File("Template.doc");
      FileInputStream fin = new FileInputStream(file);
      HWPFDocument doc = new HWPFDocument(fin);
      doc.getRange().replaceText("Haha\n", false);
      FileOutputStream fout = new FileOutputStream("Test.doc");
      doc.write(fout);
      fout.close();
      fin.close();
  }
  }
  </code></pre>