Aspose-words-22.12.jar causes java.lang.NullPointerException
while using {PAGE \* MERGEFORMAT}
{NUMPAGES \* MERGEFORMAT}
tags in word template files, when Row.remove()
is called before document.save()
.
It is working fine with ‘aspose-words-15.11.jar’
Error:
java.lang.NullPointerException
at com.aspose.words.zzXur.zzYeB(Unknown Source)
at com.aspose.words.zzXur.zzab(Unknown Source)
at com.aspose.words.zzVSs.zzzD(Unknown Source)
at com.aspose.words.zzWL.zzab(Unknown Source)
at com.aspose.words.zzXXz.zzab(Unknown Source)
at com.aspose.words.zzY9j.zzab(Unknown Source)
at com.aspose.words.zzZLe.zzab(Unknown Source)
at com.aspose.words.zzVSs.zzWpk(Unknown Source)
at com.aspose.words.zzVSs.zzab(Unknown Source)
at com.aspose.words.Document.zzab(Unknown Source)
at com.aspose.words.zzWDc.zzYCO(Unknown Source)
at com.aspose.words.zzWDc.zzab(Unknown Source)
at com.aspose.words.zzWK2.zzab(Unknown Source)
at com.aspose.words.Document.zzYCO(Unknown Source)
at com.aspose.words.Document.zzab(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
Sample Code:
try
{
merge.executeWithRegions(dataSet);
doc.updateFields();
NodeCollection <?> coll = doc.getChildNodes(NodeType.TABLE, true);
for (Object obj : coll)
{
Table t = (Table)obj;
RowCollection rows = t.getRows();
for (Object row : rows)
{
Row rw = (Row)row;
if (rw != null)
{
if (rw.toString(SaveFormat.TEXT).trim().isEmpty())
{
rw.remove();
}
}
}
}
doc.save(strPath + "testoutputdoc.pdf");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}