Can you help me to fix asap following error
java.lang.NullPointerException: Cannot invoke "com.aspose.words.Node.getNodeType()" because "this.zzY6" is null
at com.aspose.words.zzXp7.getLength(Unknown Source)
at com.aspose.words.zzXp7.zzYps(Unknown Source)
at com.aspose.words.zzXp7.zzZs(Unknown Source)
at com.aspose.words.Node.zzYt9(Unknown Source)
at com.aspose.words.zzWK2.zzZqs(Unknown Source)
at com.aspose.words.zzWf5.zzgp(Unknown Source)
at com.aspose.words.zzZeB.zzVZN(Unknown Source)
at com.aspose.words.zzZeB.zzXLp(Unknown Source)
at com.aspose.words.zzZeB.zzXos(Unknown Source)
at com.aspose.words.zzX7D.zzA5(Unknown Source)
at com.aspose.words.zzX7D.getText(Unknown Source)
at com.aspose.words.zzX7D.zzWxM(Unknown Source)
at com.aspose.words.zzX7D.zzYM2(Unknown Source)
at com.aspose.words.zzY6c.zzWWU(Unknown Source)
at com.aspose.words.zzY6c.zzYLb(Unknown Source)
at com.aspose.words.zzYf7.zzWpl(Unknown Source)
at com.aspose.words.zzYf7.zzWlF(Unknown Source)
at com.aspose.words.zzYf7.zzXUS(Unknown Source)
at com.aspose.words.zzYf7.zzWWq(Unknown Source)
at com.aspose.words.zzYf7.zzWPK(Unknown Source)
at com.aspose.words.zzYf7.zzgp(Unknown Source)
at com.aspose.words.zzYf7.zzqg(Unknown Source)
at com.aspose.words.zzYf7.zzWxK(Unknown Source)
at com.aspose.words.zzpD.zzwE(Unknown Source)
at com.aspose.words.zzpD.zzYZB(Unknown Source)
at com.aspose.words.zzpD.zzwE(Unknown Source)
at com.aspose.words.zzpD.zzPn(Unknown Source)
at com.aspose.words.zzpD.zzWwq(Unknown Source)
at com.aspose.words.zzWC2.zzWwq(Unknown Source)
at com.aspose.words.zzYf7.zzqg(Unknown Source)
at com.aspose.words.zzYf7.zzWxK(Unknown Source)
at com.aspose.words.zzpD.zzwE(Unknown Source)
at com.aspose.words.zzpD.zzYZB(Unknown Source)
at com.aspose.words.zzpD.zzwE(Unknown Source)
at com.aspose.words.MailMerge.zzwE(Unknown Source)
at com.aspose.words.MailMerge.executeWithRegions(Unknown Source)
at com.test.asynctest.ReportAsync.createWord(ReportAsync.java:1769)
at com.test.asynctest.ReportAsync.getBulkTestCaseForPDFExport(ReportAsync.java:571)
at com.test.asynctest.ReportAsync$$FastClassBySpringCGLIB$$d6421459.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
@kalpeshAspose1997 can you please provide more details to allow us replicate your problem, like the Aspose.Words version that you are using, the document that you are processing and if it’s possible the code snippet in where you got that exception?
Aspose.Words version : 22.11
artifactId : aspose-words
java : jdk17
is it’s possible we can connect on zoom or else call tool?
In code I’m trying to add 4 level nested table within if condition so you can send me example for same as well
@kalpeshAspose1997 sorry this is the only channel available to provide support.
Additionally, what method are you using to insert the tables (like you are using DocumentBuilder or another one). And, again, if you isolate and post the fragment of code that is throwing the exception will be helpful since I don’t know to what node are you requesting the NodeType
.
facing error on line number : 17764
image.png (12.9 KB)
I have use DataSet and DataTable Classes
@kalpeshAspose1997 which line is producing the error, I can’t see line numbers in the image that you posted.
oho, sorry for that
line : doc.getMailMerge().executeWithRegions(mainDataSet);
producing the error, let me know if have any doubt
template : image.png (15.2 KB)
@kalpeshAspose1997 sorry, after several attempts, I can’t reproduce your issue. It would be very helpful if you isolate and post the code that is throwing the exception, along with the template file that you are using.
could you please send me an example for a 4th level nested table with IF condition added to the template(as merge field) using the help of DataSet and DataTable classes so can fix it
@kalpeshAspose1997 there is an example using 4 levels deep table, this code is based in the Aspose example code in GitHub:
public static void main(String[] args) throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Normally, MERGEFIELDs contain the name of a column of a mail merge data source.
// Instead, we can use "TableStart:" and "TableEnd:" prefixes to begin/end a mail merge region.
// Each region will belong to a table with a name that matches the string immediately after the prefix's colon.
builder.startTable();
builder.insertCell();
builder.insertField(" MERGEFIELD TableStart:Customers");
builder.startTable();
builder.insertCell();
// This MERGEFIELD is inside the mail merge region of the "Customers" table.
// When we execute the mail merge, this field will receive data from rows in a data source named "Customers".
builder.write("Orders for ");
builder.insertField(" MERGEFIELD CustomerName");
builder.write(":");
// Create column headers for a table that will contain values from a second inner region.
builder.startTable();
builder.insertCell();
builder.write("Item");
builder.insertCell();
builder.write("Quantity");
builder.endRow();
// Create a second mail merge region inside the outer region for a table named "Orders".
// The "Orders" table has a many-to-one relationship with the "Customers" table on the "CustomerID" column.
builder.insertCell();
builder.insertField(" MERGEFIELD TableStart:Orders");
builder.insertField(" MERGEFIELD ItemName");
builder.insertCell();
builder.insertField(" MERGEFIELD TableStart:Quantities");
builder.startTable();
builder.insertCell();
builder.insertField(" MERGEFIELD Quantity");
builder.endRow();
builder.endTable();
builder.insertField(" MERGEFIELD TableEnd:Quantities");
// End the inner region, and then end the outer region. The opening and closing of a mail merge region must
// happen on the same row of a table.
builder.insertField(" MERGEFIELD TableEnd:Orders");
builder.endTable();
builder.endRow();
builder.endTable();
builder.insertField(" MERGEFIELD TableEnd:Customers");
builder.endRow();
builder.endTable();
// Create a dataset that contains the two tables with the required names and relationships.
// Each merge document for each row of the "Customers" table of the outer merge region will perform its mail merge on the "Orders" table.
// Each merge document will display all rows of the latter table whose "CustomerID" column values match the current "Customers" table row.
doc.save("C:\\Temp\\output.docx", SaveFormat.DOCX);
DataSet customersAndOrders = createDataSet();
doc.getMailMerge().executeWithRegions(customersAndOrders);
doc.save("C:\\Temp\\outputMerge.docx", SaveFormat.DOCX);
}
private static DataSet createDataSet() {
// Create the outer mail merge
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.getColumns().add("CustomerID");
tableCustomers.getColumns().add("CustomerName");
tableCustomers.getRows().add(1, "John Doe");
tableCustomers.getRows().add(2, "Jane Doe");
// Create the table for the inner merge
DataTable tableOrders = new DataTable("Orders");
tableOrders.getColumns().add("CustomerID");
tableOrders.getColumns().add("ItemName");
tableOrders.getRows().add(1, "Hawaiian");
tableOrders.getRows().add(2, "Pepperoni");
tableOrders.getRows().add(2, "Chicago");
DataTable tableQuantities = new DataTable("Quantities");
tableQuantities.getColumns().add("ItemName");
tableQuantities.getColumns().add("Quantity");
tableQuantities.getRows().add("Hawaiian", 1);
tableQuantities.getRows().add("Hawaiian", 2);
tableQuantities.getRows().add("Pepperoni", 1);
tableQuantities.getRows().add("Pepperoni", 2);
tableQuantities.getRows().add("Chicago", 3);
// Add both tables to a data set
DataSet dataSet = new DataSet();
dataSet.getTables().add(tableCustomers);
dataSet.getTables().add(tableOrders);
dataSet.getTables().add(tableQuantities);
// The "CustomerID" column, also the primary key of the customers table is the foreign key for the Orders table
dataSet.getRelations().add(tableCustomers.getColumns().get("CustomerID"), tableOrders.getColumns().get("CustomerID"));
dataSet.getRelations().add(tableOrders.getColumns().get("ItemName"), tableQuantities.getColumns().get("ItemName"));
return dataSet;
}