getting no such method error in java

2019-09-05 07:18发布

问题:

I am getting the following error as shown below

java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.addMergedRegion(Lorg/apache/poi/hssf/util/Region;)I
        at net.sf.jasperreports.engine.export.JRXlsExporter.createMergeRegion(JRXlsExporter.java:440)
        at net.sf.jasperreports.engine.export.JRXlsExporter.initCreateCell(JRXlsExporter.java:419)
        at net.sf.jasperreports.engine.export.JRXlsExporter.createTextCell(JRXlsExporter.java:381)
        at net.sf.jasperreports.engine.export.JRXlsExporter.exportText(JRXlsExporter.java:314)
        at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportPage(JRXlsAbstractExporter.java:381)

i am using the below poi jars as shown in the class path and also jasperreports 1.2.5 jar please advise i have upgraded poi jars from 2.5 to 3 so please advise do i need to upgrade jasperreports-1.2.5.jar also to be in synch with the latest poi jars

<classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/poi-3.5-FINAL.jar"/>
    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/poi-contrib-3.5-final.jar"/>
    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/poi-scratchpad-3.5-FINAL.jar"/>
    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/dom4j-1.6.1.jar"/>  
    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/poi-ooxml-3.5-FINAL.jar"/>

    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/poi-ooxml-schemas-3.6.jar"/>
    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/xmlbeans-2.3.0.jar"/>
    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/poi-ooxml-schemas-3.10-FINAL.jar"/>
    <classpathentry exported="true" kind="lib" path="thirdparty/POI-3.5/jsr173_1.0_api.jar"/>

although i have done some analysis and found this url http://community.jaspersoft.com/questions/531433/save-excel-jasperviewer which suggest with poi up gradation i should upgrade my jasper jars also

for jasper reports i have not upgraded i am using jasper reports 1.2.5 jar should i upgrade that also , folks please advise

回答1:

java.lang.NoSuchMethodError is typical error when not using correct version of libraries.

Jasper report uses multiple libraries which can be found in its distribution (in folder lib), they should all be included in classpath

Jasper report releases

If you are using Jasper reports 1.2.5 this is its release Jasper report v 1.2.5. You will find correct libraries to include in your classpath in folder lib.

However there is no doubt that is better to upgrade to latest version (when posted this answer 6.2.0), specially if you need to export to xlxs, ooxml, XSSF, this it not supported in 1.2.5.

Note: jasper report has change is file format definition from DTD to XSD schema in newer version so you may need to change your headers in .jrxml (or use old .jrxml compiler)