0

我不确定此错误消息实际上指向什么。需要明确的是,我知道 NullPointerException 是什么,但我无法弄清楚不应该是什么 null。有人知道是什么导致这个错误是空的吗?

谢谢。

com.lowagie.text.DocumentException: java.lang.NullPointerException
    at com.lowagie.text.pdf.PdfDocument.add(Unknown Source)
    at com.lowagie.text.Document.add(Unknown Source)
...
Caused by: java.lang.NullPointerException
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.calculateHeights(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.setTotalWidth(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.PdfPCell.getMaxHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPRow.calculateHeights(Unknown Source)
    at com.lowagie.text.pdf.PdfPRow.getMaxHeights(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.calculateHeights(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.setTotalWidth(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)
    ... 97 more

有问题的代码:

    this.getDocument().open();
    Element body = this.getBody();
    System.out.println(body);
    System.out.println(this.getDocument().toString());
    this.getDocument().add(body);//it errors out here!
    this.getDocument().close();

调试语句返回:

com.lowagie.text.pdf.PdfPTable@1fa0c8f
com.lowagie.text.Document@14eb497
4

1 回答 1

1

我得到了完全相同的错误和堆栈跟踪,并通过切换到 OpenPDF 解决了这个问题。

OpenPDF 基于 iText 4 并且有一些额外的错误修复和 NPE 修复。OpenPDF 正在积极维护中。

https://github.com/LibrePDF/OpenPDF

于 2018-04-24T07:35:03.393 回答