Aspose Word for Java NullPointer exception

Hello,

Very confusing error.
Aspose mail merge was working fine for me for months, I added a method to perform a simple merge and now nothing works. None of the fields in either array are null or empty (I printed them both out).
Can you please advise?

code:

String[] names =
    {"EMAIL", "FIRM","MI","FAX","PHONE","TITLE", "FIRST", "MI", "LAST", "ADDRESS","LINE_2",
    "CITY","STATE","ZIP","COUNTY","EFF_DATE","AOP1","AOP2","AOP4","AOP5","AOP6"};

Object[] obj = {"test@dpn.com",clientChkName, clientMName,clientFax, clientPhone ,"Sir",
    clientFName , clientMName , clientLName ,cls(clientAddr.getAddress1()), cls(clientAddr.getAddress2()) ,cls(clientAddr.getCity()),
    cls(clientAddr.getState()), zip, cls(clientAddr.getCounty()),appEffDate,"AOP1","AOP2","AOP4","AOP5","AOP6"};

System.out.println("Names:" + names.length + " Objs:" + obj.length);

for (int t = 0; t < names.length; t++)
{
    System.out.println(names[t]);
    System.out.println((String)obj[t]);
    System.out.println();
}

try
{
    doc = new Document(fileName);
    System.out.println("filename::" + fileName);
    // adding Merge Field Event Handler
    doc.getMailMerge().addMergeFieldEventHandler(this);
    doc.getMailMerge().execute(names, obj);

}
catch (Exception e) { System.out.println(e + "- MergeUtil error -"); e.printStackTrace(); }

ERROR GENERATED:

**filename::/opt/jakarta-tomcat-4.1.31/webapps/AMS_WEB/files/application_forms/ArchDoc.doc**
**java.lang.NullPointerException- MergeUtil error -**
**java.lang.NullPointerException**
**at com.aspose.words.hw.d(Unknown Source)**
**at com.aspose.words.hw.a(Unknown Source)**
**at com.aspose.words.MailMerge.execute(Unknown Source)**
**at com.aspose.words.MailMerge.execute(Unknown Source)**
**at com.core.beans.MergeUtil.executeAppMerge(MergeUtil.java:95)**
**at com.core.servlets.DocMergeServlet.doPost(DocMergeServlet.java:331)**
**at com.core.servlets.DocMergeServlet.doGet(DocMergeServlet.java:48)**
**at javax.servlet.http.HttpServlet.service(HttpServlet.java:696)**
**at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)**
**at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)**
**at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)**
**at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)**
**at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)**
**at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)**
**at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)**
**at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)**
**at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)**
**at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)**
**at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)**
**at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)**
**at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)**
**at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)**
**at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)**
**at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)**
**at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)**
**at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)**
**at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)**
**at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)**
**at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)**
**at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)**
**at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)**
**at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)**
**at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)**
**at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)**
**at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)**
**at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)**
**at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)**
**at java.lang.Thread.run(Thread.java:534)**

Hi, Kaylon,
Can you attach the doc and the MergeFieldEventHandler method body?
Best regards,

public void mergeField(Object sender, MergeFieldEventArgs e)
{
    // DecimalFormat df = new DecimalFormat("$###,###.00"); 
    String value = (String)e.getFieldValue();

    if ("EMAIL".equals(e.getFieldName()) || "EMAIL_".equals(e.getFieldName()) || "BKR_ZIP".equals(e.getFieldName()) || "TIME".equals(e.getFieldName()) || "NO_ATTYS".equals(e.getFieldName()) || "SOURCE".equals(e.getFieldName()) || "ZIP".equals(e.getFieldName()))
    {
        e.setText(value);
    }
    else if ("PHONE".equals(e.getFieldName()) || "FAX".equals(e.getFieldName()))
    {
        e.setText(StringUtilities.formatPhoneNum(value));
    }
    else if ("XD".equals(e.getFieldName()) || "X_DATE".equals(e.getFieldName()) || "BKR_Plus4".equals(e.getFieldName()) || "Plus4".equals(e.getFieldName()) || "EFF_DATE".equals(e.getFieldName()))
    {
        e.setText(value);
    }
    else if ("COST".equals(e.getFieldName()))
    {
        value = "$" + value;
        e.setText(value);
    }
    else if ("INITIAL_PAYMT".equals(e.getFieldName()) || "AGG".equals(e.getFieldName()) || "LIM".equals(e.getFieldName()) || "PREM".equals(e.getFieldName()) || "AD_FEE".equals(e.getFieldName()) || "DEDUCT".equals(e.getFieldName()))
    {
        if (value.equalsIgnoreCase("NA"))
            value = null;

        if (value != null && value.indexOf(’.’) < 0)
            value += ".00";

        if (value == null)
        {
            System.out.println("Value:" + value + " Field:" + e.getFieldName());
            value = "0.00";
        }

        value = "$" + StringUtilities.formatNumber("###,###.##", Float.parseFloat(value));
        e.setText(value);
    }
    else if ("POL_NO".equals(e.getFieldName()))
    {

        if (value.indexOf("L") >= 0)
        {
            e.setText(value);
        }

        else if (value.equalsIgnoreCase("PNNA"))
        {
            e.setText("");
        }

        else
        {

            Integer number = new Integer(value);
            char[] c = number.toString().toCharArray();
            e.setText("LPL " + c[0] + " " + c[1] + c[2] + " " + c[3] + c[4] + " " + c[5] + c + "-" + c[7]);
        }
    }

    System.out.println(e.getFieldName() + ":" + value);

}

Hi, Kaylon,
Your doc is in RTF format (despite of extension). Aspose.Words for Java not supports RTF yet. For workaround you have to save the doc in DOC format manually (in MS Word).
Regards,

We are happy to tell you that the new version of Aspose.Words for Java was released. Support of Rtf and Odt formats were added in this release!

(11)