在将本章添加到文档中后,我尝试将章节添加到章节中。 这是我的代码:
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 中失败。我在“chapter = new Chapter(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)
我想知道调用 new Chapter(int) 的正确方法是什么。
最佳答案
您发现了一个错误。它已在 SVN 存储库中修复:https://sourceforge.net/p/itext/code/6074/
当您创建没有标题的章节
时,就会出现此问题。
关于java - 在 iText 5.4.4 中调用 new Chapter(int) 时出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20053476/