gpt4 book ai didi

java.lang.NoSuchMethodError : org. apache.poi.hssf.usermodel.HSSFSheet.setColumnWidth(II)V

转载 作者:搜寻专家 更新时间:2023-11-01 03:59:27 27 4
gpt4 key购买 nike

我正在尝试生成 Jasper Excel 报告。我收到类似

的异常
java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.setColumnWidth(II)V
at net.sf.jasperreports.engine.export.JRXlsExporter.setColumnWidth(JRXlsExporter.java:212)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.setColumnWidths(JRXlsAbstractExporter.java:654)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportPage(JRXlsAbstractExporter.java:527)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:423)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:207)
at com.pagesolutions.controller.ReportingController.doGet(ReportingController.java:177)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

我的 Java 代码

if(formatType.matches("XLS")){
String jrxml = "/home/madhu/report1.jrxml";
list = (List<Reports>) session.getAttribute("customersList");
//InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(jrxml);
try {
//jasperReport = JasperCompileManager.compileReport(jrxml);
//jasperDesign = JRXmlLoader.load(jrxml);
jasperReport = JasperCompileManager.compileReport(jrxml);
JRDataSource datasource = new JRBeanCollectionDataSource(list, true);
jasperPrint = JasperFillManager.fillReport(jasperReport, null, datasource);
String output="/home/madhu/reports/report.xls";
//JasperExportManager.exportReportToPdfFile(jasperPrint, output);
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, output);
exporterXLS.exportReport();
ServletOutputStream servletOutputStream = response.getOutputStream();
String fileName = "report.xls";
FileInputStream fileToDownload = new FileInputStream(output);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename="+ fileName);
ByteArrayOutputStream output1 = new ByteArrayOutputStream();
int readBytes = 0;
byte[] buffer = new byte[10000];
while ((readBytes = fileToDownload.read(buffer, 0, 10000)) != -1) {
servletOutputStream.write(buffer, 0, readBytes);
}

output1.flush();
output1.close();
fileToDownload.close();
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

我已经在我的库中添加了 poi-3.2-FINAL.jar 文件,但仍然出现上述异常

谁能帮帮我....

最佳答案

如果项目已构建,但您在运行时遇到此错误,这可能只意味着一件事:您正在构建和运行不同的库版本。您构建的版本具有此方法,而您运行的版本则没有。也可能发生在类路径上有多个版本并且首先加载了错误的版本。我不知道你是如何构建项目的,但如果你使用某种依赖管理器,请分析重复 POI 版本的结构。如果你没有使用任何依赖管理器......那么......手动确保库在构建和运行时匹配,但你真的应该切换到一个为你做这件事的构建工具,以便 Jasper 可以自动拖入它所依赖的正确版本。

重要提示:
由于 Jasper 已经依赖于 POI,因此您的项目没有理由再次声明该依赖性。它只是在自找麻烦,如您现在看到的那样。您只需声明对 Jasper 的依赖,然后让依赖管理器拖入正确版本的 POI。不知何故,即使在高级开发人员中,对依赖管理的根本误解也很普遍。

另一方面,如果您依赖的另一个库也拖入了不同版本的 POI,则您需要找到两个第三方库的兼容版本(以便它们需要相同的 POI),或者明确从其中之一中排除 POI,祈祷一切顺利。

关于java.lang.NoSuchMethodError : org. apache.poi.hssf.usermodel.HSSFSheet.setColumnWidth(II)V,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30069316/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com