NutzCN Logo
问答 DocumentException: java.lang.ArrayIndexOutOfBoundsException: -1 报错
发布于 29天前 作者 qq_a673389b 52 次浏览 复制 上一个帖子 下一个帖子
标签:
报错信息:

[INFO ] 2017-11-18 12:54:20,889 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:488) - 姓名
[INFO ] 2017-11-18 12:54:20,889 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:491) - [数学]
[INFO ] 2017-11-18 12:54:20,889 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:491) - [英语]
[INFO ] 2017-11-18 12:54:20,889 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:491) - [历史]
[INFO ] 2017-11-18 12:54:20,890 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:491) - [语文]
[INFO ] 2017-11-18 12:54:20,890 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:494) - 总分
[INFO ] 2017-11-18 12:54:20,890 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:498) - 时波
[INFO ] 2017-11-18 12:54:20,890 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:498) - 80
[INFO ] 2017-11-18 12:54:20,891 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:498) - 89
[INFO ] 2017-11-18 12:54:20,891 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:498) - 90
[INFO ] 2017-11-18 12:54:20,891 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:498) - 92
[INFO ] 2017-11-18 12:54:20,891 cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:498) - 351
DocumentException: java.lang.ArrayIndexOutOfBoundsException: -1
	at com.lowagie.text.pdf.PdfPRow.writeCells(Unknown Source)
	at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
	at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
	at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
	at com.lowagie.text.pdf.ColumnText.goComposite(Unknown Source)
	at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
	at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
	at com.lowagie.text.pdf.PdfDocument.addPTable(Unknown Source)
	at com.lowagie.text.pdf.PdfDocument.add(Unknown Source)
	at com.lowagie.text.Document.add(Unknown Source)
	at cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.sendEmail(ScScoreController.java:507)
	at cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController.mail(ScScoreController.java:447)
	at cn.wizzer.app.web.modules.controllers.platform.sc.ScScoreController$FM$mail$1880b8f4667c076aa75f94d27a83b1d7.invoke(ScScoreController.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:36)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:31)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
[DEBUG] 2017-11-18 12:54:22,138 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [POST]URI=/platform/sc/score/s 1648ms


java代码:
public void sendEmail(String sno,List list) throws DocumentException, IOException {
        //创建文件
        Document document = new Document();
        //建立一个书写器
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:\\student\\wk-pdffile\\"+sno+".pdf"));
        //打开文件
        document.open();
        //写入中文
        BaseFont font = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font fontChinese = new Font(font);
        //添加内容
        document.add(new Paragraph(list.get(0)+"的成绩"));
        PdfPTable table = new PdfPTable(2);
        List<PdfPRow> listRow = table.getRows();
        List<Sc_course> courseList = scCourseService.query(Cnd.orderBy().asc("id"));
        PdfPCell cells1[]= new PdfPCell[list.size()-1];
        cells1[0] = new PdfPCell(new Paragraph("姓名",fontChinese));
        log.info("姓名");
        for(int i=0;i<courseList.size();i++){
            cells1[i+1] = new PdfPCell(new Paragraph(courseList.get(i).getName(),fontChinese));
            log.info(new Paragraph(courseList.get(i).getName()));
        }
        cells1[list.size()-2] = new PdfPCell(new Paragraph("总分",fontChinese));
        log.info("总分");
        PdfPCell cells2[]= new PdfPCell[list.size()-1];
        for(int i=0;i<list.size()-1;i++){
            cells1[i] = new PdfPCell(new Paragraph(list.get(i).toString(),fontChinese));
            log.info(list.get(i).toString());
        }
        PdfPRow row1 = new PdfPRow(cells1);
        PdfPRow row2 = new PdfPRow(cells2);
        //把第每行添加到集合
        listRow.add(row1);
        listRow.add(row2);
        //把表格添加到文件中
        document.add(table);
        //关闭文档
        document.close();
        //关闭书写器
        writer.close();
    }
5 回复

507行是 document.add(table);

性命攸关,求大神解答

你得绑定源码了

另外,有时候升级版本也能解决,我指itext的版本

找到了,cells2写成了cells1,太粗心了。。。

添加回复
请先登陆
回到顶部