2

I have included the dom4j-1-6.jar,poi 3.9 jar,poi ooxml schemas 3.9 jar,poi ooxml 3.9 jar,xmlbeans-2.3.0.jar in my class path.i have used syntax like below

InputStream ExcelFileToRead = new FileInputStream(relative+"/"+docName);
         XSSFWorkbook  wb_hssf  = new XSSFWorkbook(ExcelFileToRead);

Im getting the following error,

java.lang.NoSuchMethodError: org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Ljava/io/InputStream;)V
    at com.admin.upload_images.doPost(upload_images.java:1057)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)

2 Answers 2

3

There's an Apache POI FAQ entry covering virtually this case, which you should read. Basically though, at runtime, you are not using the POI jars you compiled against. Instead, you are somehow using a different version. This could be because you deployed different jars, it could be because your runtime or container or framework shipped other POI jars, or some other mistake. As per this POI FAQ all POI jars must be from the same version too.

So, you need to review your classpath at runtime, with the help of the snippet from the FAQ if you can't spot what's wrong, then remove the mis-matched POI jars so you only have the ones you used at compile time. Your code will then work

However... There are a few other issues with your code! One is that you're using an InputStream when you have a file. This, as explained in the Apache POI docs is bad as it uses lots more memory. Change it to use a File instead, eg with this

Workbook wb = WorkbookFactory.create(new File("MyExcel.xls"));

Secondly, Apache POI 3.9 is a bit old now, and there have been a huge number of bug fixes since then, so you should upgrade to the latest version (3.11 or 3.12 beta 1 as of writing)

Sign up to request clarification or add additional context in comments.

1 Comment

I encountered this exception when I included BIRT. I realized BIRT (4.5.0) consumes POI (3.9.0) while I constructed my framework with POI 3.13.0.
0

As the exception suggest even though you are include a version in which the method exists, the build is considering an older version in which the method does not exists. To test this check your maven dependency tree and remove the older versions. It could also be possible that an older version is comming from the container as well so check it properly.

5 Comments

,i have removed all the old versions of jar.I have checked.
If you are using eclipse the do a F3 on the class which can show you the jar path. Check if the version is correct.
I am using simply NetBeans IDE @Raghuveer
So if you are comfortable with it then see where the jar for that class exists
Once you get which version it is extract the jar and see if the said class file exists in the jar and also the method using JDGUI tool (download it if you dont have it) from jd.benow.ca/jd-gui/downloads/jd-gui-0.3.6.windows.zip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.