Apache POI java.lang.NoSuchMethodError

Tags: , ,



My code is below:

 import java.util.*;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.IOException;

 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.xssf.usermodel.*;

 public class ExcelRead{

     public static void main(String[] args){
        String docName = "C:\Users\Name\Desktop\excelExample.xlsx";
        try{
            InputStream xlsxDoc = new FileInputStream(docName);
            XSSFWorkbook wb = new XSSFWorkbook(xlsxDoc);
            XSSFSheet sheet = wb.getSheetAt(0);
            System.out.println(sheet.getSheetName());          
        }
        catch(Exception e){  
            e.printStackTrace();
        }
     }
}

And the error code I get is:

Exception in thread "main" java.lang.NoSuchMethodError: 
org.apache.poi.util.POILogger.log(ILjava/lang/Object;)V
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:313)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:163)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:131)
at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:559)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:112)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:83)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:128)
at org.apache.poi.openxml4j.opc.ZipPackagePart.<init>(ZipPackagePart.java:78)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:243)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:673)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:274)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:258)
at AristocratProject_1.ExcelRead.main

The dependencies for Apache that I have added to my netbeans library are:

poi-3.17.jar
poi-ooxml-3.11.jar
xmlbeans-2.6.0.jar

And from here I pretty much have no idea what to do. Can anyone tell me if my code is wrong or what other dependencies I need?

Answer

Ok, so as rgettman explained, I had to update my poi-ooxml-3.11.jar to poi-ooxml-3.17.jar, which can be done by just redownloading the binary source file and extracting the .zip file. After both were updated, I got another error, and this was fixed by adding the commons-collections4-4.1.jar and poi-ooxml-schemas-3.17.jar. After adding these dependencies, my code ran. Hope this helps anyone in the future.



Source: stackoverflow