在iText 5.4.4中调用new Chapter(int)时出现NullPointerException

时间:2013-11-18 17:02:51

标签: java itext

在本章添加到文档后,我尝试将章节添加到章节中。 这是我的代码:

Chapter chapter = new Chapter("chapter1", 1);
chapter.addSection("section1");
document.add(chapter);

chapter = new Chapter(1);
chapter.addSection("section2");
document.add(chapter);

这适用于5.0.4版(书籍版),但最新的5.4.4失败了。我在第一章“章节=新章(1);”中获得了NullPointerException。

这是错误堆栈:

Exception in thread "main" java.lang.NullPointerException
at com.itextpdf.text.Section.<init>(Section.java:176)
at com.itextpdf.text.Chapter.<init>(Chapter.java:82)
at mihoTest.MihoTest03.main(MihoTest03.java:36)

Jus想知道调用新章节(int)的正确方法是什么。

1 个答案:

答案 0 :(得分:0)

你发现了一个错误。它已在SVN存储库中修复:https://sourceforge.net/p/itext/code/6074/

创建没有标题的Chapter时会出现问题。