Bug 47074 - java.lang.NoSuchMethodError: org.apache.poi.POIDocument.<init>(
Summary: java.lang.NoSuchMethodError: org.apache.poi.POIDocument.<init>(
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: POIFS (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-22 07:18 UTC by Kishore
Modified: 2009-04-22 07:26 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kishore 2009-04-22 07:18:13 UTC
Hi Iam trying to read excel file as per the program (downloaded  from internet, attached for reference here) But i am getting below error:



got 'SummaryInformation' event for path '\'.
got 'DocumentSummaryInformation' event for path '\'.
got 'Workbook' event for path '\'.
  trying DirectoryNode 'Root Entry'
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.POIDocument.<init>(Lorg/apache/poi/poifs/filesystem/DirectoryNode;Lorg/apache/poi/poifs/filesystem/POIFSFileSystem;)V
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:225)
	at com.lehman.pcs.bcu.util.POIFSExtract$MyPOIFSReaderListener.processPOIFSReaderEvent(POIFSExtract.java:53)
	at org.apache.poi.poifs.eventfilesystem.POIFSReader.processProperties(POIFSReader.java:261)
	at org.apache.poi.poifs.eventfilesystem.POIFSReader.read(POIFSReader.java:97)
	at com.lehman.pcs.bcu.util.POIFSExtract.main(POIFSExtract.java:29)


I am using jars of version as below :

poi-3.1-FINAL.jar
poi-scratchpad-3.0.1-FINAL.jar
poi-contrib-3.1-FINAL.jar
Comment 1 Kishore 2009-04-22 07:19:27 UTC
The attached code is pasted below.

package com.lehman.pcs.bcu.util;

import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 

import org.apache.poi.hssf.record.RecordFormatException; 
import org.apache.poi.hssf.usermodel.HSSFWorkbook; 
import org.apache.poi.poifs.eventfilesystem.POIFSReader; 
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent; 
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener; 
import org.apache.poi.poifs.filesystem.DirectoryNode; 
import org.apache.poi.poifs.filesystem.POIFSDocumentPath; 
import org.apache.poi.poifs.filesystem.POIFSFileSystem; 

public class POIFSExtract { 

    public static void main(String[] args) throws Exception { 
        //if (args == null || args.length < 1) 
            //throw new Exception("\n->no input, no output<-"); 


        String fileName1 = "H:\\Kishor\\Research\\EmailWorkFlow\\Web_Server_Comparison.xls";
        POIFSFileSystem fs = new POIFSFileSystem(new 
        		FileInputStream(fileName1)); 

        POIFSReader reader = new POIFSReader(); 
        reader.registerListener(new MyPOIFSReaderListener(fs)); 
        reader.read(new FileInputStream(fileName1)); 
    } 

    static class MyPOIFSReaderListener implements POIFSReaderListener { 

        private POIFSFileSystem fs; 

        public MyPOIFSReaderListener(POIFSFileSystem fs) { 
            this.fs = fs; 
        } 

        public void processPOIFSReaderEvent(POIFSReaderEvent event) { 

            String name = event.getName(); 
            POIFSDocumentPath path = event.getPath(); 
            System.out.println("got '" + name + "' event for path '" + path 
            			+ "'."); 

            if (name.endsWith("Workbook") || name.endsWith("WORKBOOK")) { 
                try { 
                    DirectoryNode dir = resolveDir(fs, 
                    		event.getPath().toString()); // converting it to DirectoryNode 
                    System.out.println("  trying DirectoryNode '" + 
                    		dir.getName() + "'"); 
                    HSSFWorkbook wb = new HSSFWorkbook(dir, fs, true); 
                    //invoke HSSFWorkbook constructor passing this directory to it 
                    System.out.println("  !!! success: workbook with " + 
                    		wb.getNumberOfSheets() + " sheets."); 
                } 
                catch (RecordFormatException e) { 
                    // MS Graph charts are stored in "Workbook" stream too 
                    System.out.println("  skipping embedded MS Graph object!"); 
                } 
                catch (Exception e) { 
                    System.out.println("  " + e.getMessage()); 
                    throw new RuntimeException(e.getMessage()); 
                } 
            } 
        } 

        static DirectoryNode resolveDir(POIFSFileSystem filesystem, 
        		String path) throws FileNotFoundException { 
            DirectoryNode dir = filesystem.getRoot(); 

            for (String token : path.split("\\" + File.separator)) { 
                if (!token.equals("") && !token.equals(File.separator)) 
                    dir = (DirectoryNode) dir.getEntry(token); 
            } 

            return dir; 
        } 
    } 
}
Comment 2 Nick Burch 2009-04-22 07:26:57 UTC
You almost certainly have a different version of poi on your run classpath to your compile classpath. Please see the faq on the site for how to test which jars you're really running with.