0

I am trying to read excel both(.xls and .xlsx) using java. I was able to read xlsx properly. But when I am reading xls file with the following code

final HSSFCell cell = row.getCell(i, Row.RETURN_BLANK_AS_NULL);

I am getting error

java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFRow.getCell(ILorg/apache/poi/ss/usermodel/Row$MissingCellPolicy;)Lorg/apache/poi/hssf/usermodel/

Please help. I am using poi-3.9-20121203.jar

Gagravarr
  • 47,320
  • 10
  • 111
  • 156
Amar
  • 421
  • 1
  • 6
  • 17

1 Answers1

1

This is covered in the Apache POI FAQ. If you look, you'll see that you have an older copy of Apache POI lurking somewhere in your classpath, so you're in fact running with a mixture of two versions. That isn't supported - all the POI jars need to be from the same version!

The FAQ entry on the topic has some sample code you can use to look up which Jar is actually being used, so you can hopefully track down that older jar. You'd want to do something like:

ClassLoader classloader =
   org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
             "org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
System.out.println("Core POI came from " + path);

That will print out where one of the core POI classes comes from, when that reports the jar you expect you should be fine!

Gagravarr
  • 47,320
  • 10
  • 111
  • 156