使用Apache POI API读取“.doc”文件时获取“java.lang.ArrayIndexOutOfBoundsException”

时间:2012-05-31 10:18:48

标签: java apache-poi

以下是我得到的例外情况:

  

线程“AWT-EventQueue-0”中的异常java.lang.ArrayIndexOutOfBoundsException:20203       在org.apache.poi.util.LittleEndian.getShort(LittleEndian.java:45)       在org.apache.poi.hwpf.model.ListLevel。(ListLevel.java:120)       在org.apache.poi.hwpf.model.ListFormatOverrideLevel。(ListFormatOverrideLevel.java:48)       在org.apache.poi.hwpf.model.ListTables。(ListTables.java:88)       在org.apache.poi.hwpf.HWPFDocument。(HWPFDocument.java:267)       在org.apache.poi.hwpf.HWPFDocument。(HWPFDocument.java:157)       在com.mahesh.MyFrame.readMSDocuments(MyFrame.java:301)       在com.mahesh.MyFrame.readALLDocuments(MyFrame.java:276)       at com.mahesh.MyFrame.access $ 1(MyFrame.java:269)       at com.mahesh.MyFrame $ 2.actionPerformed(MyFrame.java:231)       在javax.swing.AbstractButton.fireActionPerformed(未知来源)       at javax.swing.AbstractButton $ Handler.actionPerformed(Unknown Source)       在javax.swing.DefaultButtonModel.fireActionPerformed(未知来源)       在javax.swing.DefaultButtonModel.setPressed(未知来源)       在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(未知来源)       at java.awt.Component.processMouseEvent(Unknown Source)       在javax.swing.JComponent.processMouseEvent(未知来源)       at java.awt.Component.processEvent(Unknown Source)       at java.awt.Container.processEvent(Unknown Source)       at java.awt.Component.dispatchEventImpl(Unknown Source)       at java.awt.Container.dispatchEventImpl(Unknown Source)       at java.awt.Component.dispatchEvent(Unknown Source)       at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)       at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)       at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)       at java.awt.Container.dispatchEventImpl(Unknown Source)       at java.awt.Window.dispatchEventImpl(Unknown Source)       at java.awt.Component.dispatchEvent(Unknown Source)       at java.awt.EventQueue.dispatchEvent(Unknown Source)       at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)       at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)       at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)       at java.awt.EventDispatchThread.pumpEvents(Unknown Source)       at java.awt.EventDispatchThread.pumpEvents(Unknown Source)       在java.awt.EventDispatchThread.run(未知来源)

这是我的代码

private void readMSDocuments(String fileToRead) {

    boolean containsEditorAndMt = false;
    String fileEditorAndMt = null;
    dataArray = null;
    try {

        fis = new FileInputStream(new File(fileToRead).getAbsolutePath());
        fs = new POIFSFileSystem(fis);
        document = new HWPFDocument(fs);
        wordExtractor = new WordExtractor(document);
        dataList = new ArrayList();
        dataArray = wordExtractor.getParagraphText();//getParagraphText() reads paragraphs so problem is each paragraph is read a single line .u can see in console
        System.out.println(dataArray.length);
        if (dataArray.length >= 0) {


            for (int k = 0; k < dataArray.length; ++k) {

                if (dataArray[k].trim().length() > 0) {

                    dataList.add(dataArray[k].trim());
                    //System.out.println(fileToRead+" "+dataArray[k].trim()+"\n");
                }
            }
        }

    }
}

有人可以帮我找出抛出异常的原因吗?

1 个答案:

答案 0 :(得分:1)

您正在使用Apache POI API:
这是此域中的错误。

您可以阅读此错误并通过this进行分析。