iText5.5.0 数据量大的时候保存文件到磁盘会出现空指针错误?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

iText5.5.0 数据量大的时候保存文件到磁盘会出现空指针错误?报错

爱吃鱼的程序员 2020-06-20 19:28:24 140

 程序执行Document.add(Element pdfPTable)的时候,如果pdfPTable内容小一般不会报错,一旦内容稍大,就会报空指针错误。

报错如下,哪位大神有碰到过的,求指教啊。

com.itextpdf.text.DocumentException: java.lang.NullPointerException
	at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:804)
	at com.itextpdf.text.Document.add(Document.java:278)
	at com.landray.kmss.qm.chart.util.concernCpl.ConcernCplDownloadController.processDownConcernPdf(ConcernCplDownloadController.java:284)
	at com.landray.kmss.qm.chart.common.actions.ConcernCplDownloadAction.downConcernPDF(ConcernCplDownloadAction.java:42)
	at sun.reflect.GeneratedMethodAccessor469.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
	at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:160)
	at com.landray.kmss.sys.config.loader.KmssStrutsRequestProcessor$2.execute(KmssStrutsRequestProcessor.java:96)
	at com.landray.kmss.third.pda.interfaces.ThirdPdaActionInterceptor.execute(ThirdPdaActionInterceptor.java:20)
	at com.landray.kmss.sys.config.loader.KmssStrutsRequestProcessor$2.execute(KmssStrutsRequestProcessor.java:99)
	at com.landray.kmss.sys.config.loader.KmssStrutsRequestProcessor.processActionPerform(KmssStrutsRequestProcessor.java:104)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
	at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
	at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:79)
	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
	at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:143)
	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
	at com.landray.kmss.sys.authentication.integration.KmssProcessingFilterProxy$VirtualFilterChain.doFilter(KmssProcessingFilterProxy.java:125)
	at com.landray.kmss.third.pda.interfaces.ThirdPdaRedirectFilter.doFilter(ThirdPdaRedirectFilter.java:102)
	at com.landray.kmss.sys.authentication.integration.KmssProcessingFilterProxy$VirtualFilterChain.doFilter(KmssProcessingFilterProxy.java:128)
	at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:246)
	at com.landray.kmss.sys.authentication.integration.KmssProcessingFilterProxy$VirtualFilterChain.doFilter(KmssProcessingFilterProxy.java:128)
	at com.landray.kmss.sys.authentication.integration.KmssProcessingFilterProxy.doFilter(KmssProcessingFilterProxy.java:49)
	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
	at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:220)
	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
	at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
	at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:120)
	at com.landray.kmss.web.filter.AcegiFilterToBeanProxy.doFilter(AcegiFilterToBeanProxy.java:35)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.landray.kmss.web.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:43)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
	at com.itextpdf.text.pdf.PdfPCell.<init>(PdfPCell.java:237)
	at com.itextpdf.text.pdf.PdfPRow.splitRowspans(PdfPRow.java:811)
	at com.itextpdf.text.pdf.ColumnText.goComposite(ColumnText.java:1790)
	at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:883)
	at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:878)
	at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:867)
	at com.itextpdf.text.pdf.PdfDocument.addPTable(PdfDocument.java:2622)
	at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:745)
	... 56 more



Java
分享到
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-20 19:28:40

    空指针的话应该不是数据量大的原因还是检查程序吧单步跟踪下

    引用来自“程序猿可爱多”的评论

    空指针的话应该不是数据量大的原因还是检查程序吧单步跟踪下

    请问这个是否支持 pdf extraction 呢?要是的话,提取text和image都可以吗?
    楼主 这个解决了吗? 同求结果 楼主 这个解决了吗? 同求结果,若能解决,必有重谢楼主问题解决了吗,同问

    我也遇到了这个问题,循环添加单元格时出了纰漏,导致最后document.add(PdfPTabletable)时出现空指针

    一定要通过cell.addElement();来添加元素!这一步后面会调用    

    publicvoidsetTotalWidth(floattotalWidth){if(this.totalWidth!=totalWidth){this.totalWidth=totalWidth;this.totalHeight=0.0F;this.calculateWidths();this.calculateHeights();}}

    这一步很重要,少了这一步后面才会空指针,

    希望你们也是这个问题

    Document.add(Element pdfPTable),我是把pdfPTable中内容拆分成多个 解决的:

    Document.add(Element pdfPTable1)

    Document.add(Element pdfPTable2)

    Document.add(Element pdfPTable3)

    0 0
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程