问题描述
- iText html转pdf的空指针异常
-
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(htmlName),
Charset.forName("UTF-8"));
document.close();以上代码,走到 XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(htmlName), Charset.forName("UTF-8")); 时报空指针异常,请问大神,错在哪里哈
解决方案
调试下,看这一行上的document writer htmlName是否有null
解决方案二:
估计XMLWorkerHelper.getInstance() 为null , 怎么都喜欢一句过的代码,我建议把上面的代码分成三行代码,很容易就是知道那里有问题了
时间: 2025-01-21 02:42:53