空指针异常,不进入循环内部

时间:2015-06-10 07:03:06

标签: java xml

要求是:如果<bby:SaleTenderType>值是电子商务,它会读取SalesOrderNum并调用所需的函数(将其他节点附加到根节点)。 <bby:SaleTenderType>不是电子商务,它应该调用其他功能。

java代码如下:

//Added for giftCard
//error
Lineitems = retailChildren.item(j).getChildNodes();
for (int z1 = 0; z1 < Lineitems.getLength(); z1++) {

    if (Lineitems.item(z1).getNodeName().equalsIgnoreCase("Return")) {
        NodeList returnChild1 = Lineitems.item(z1).getChildNodes();

        for (int z2 = 0; z2 < returnChild1.getLength(); z2++) {
            if (returnChild1.item(z2).getNodeName().equalsIgnoreCase("Tender")) {

                NodeList tenderChild = Lineitems.item(z2).getChildNodes(); //Null pointer exception
                for (int z3 = 0; z3 < tenderChild.getLength(); z3++) {

                    if (tenderChild.item(z3).getNodeName().equalsIgnoreCase("bby:SaleTenderType")) {
                        System.out.println("Inside");
                        String SaleTenderType = tenderChild.item(z3).getFirstChild().getNodeValue();

                        if (SaleTenderType.equalsIgnoreCase("eCommerce")) {

                            Lineitems = retailChildren.item(j).getChildNodes();
                            for (int i2 = 0; i2 < Lineitems.getLength(); i2++) {
                                if (Lineitems.item(i2).getNodeName().equalsIgnoreCase("Return")) {
                                    NodeList returnChild = Lineitems.item(i2).getChildNodes();
                                    for (int k = 0; k < returnChild.getLength(); k++) {
                                        if (returnChild.item(k).getNodeName().equalsIgnoreCase("c360:SalesOrder")) {
                                            String POSLOGSalesOrderNo = returnChild.item(k).getFirstChild().getNodeValue();
                                            SalesOrderNo = POSLOGSalesOrderNo.substring(2, 12);
                                            String SalesOrderNum = POSLOGSalesOrderNo.substring(0, 2);
                                            if (SalesOrderNum.equalsIgnoreCase("HD") || (SalesOrderNum.equalsIgnoreCase("SV")) || (SalesOrderNum.equalsIgnoreCase("CR")) || (SalesOrderNum.equalsIgnoreCase("CW"))) {
                                                if (!prevSalesOrder.equals(SalesOrderNo)) {

                                                    IDocEl = outdoc.createElement("IDOC");
                                                    ORDERS05.appendChild(createIDocHeader_GC(POSLOGSalesOrderNo, outdoc, EMPST, IDocEl, StoreID, true, returnChild, TRANS));
                                                    prevSalesOrder = SalesOrderNo;
                                                }
                                                IDocEl.appendChild(createE1EDP01forReturnLineItem_GC(outdoc, returnChild, StoreID));
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {

                Lineitems = retailChildren.item(j).getChildNodes();
                for (int i3 = 0; i3 < Lineitems.getLength(); i3++) {
                    if (Lineitems.item(i3).getNodeName().equalsIgnoreCase("Return")) {
                        NodeList returnChild = Lineitems.item(i3).getChildNodes();
                        for (int k = 0; k < returnChild.getLength(); k++) {
                            if (returnChild.item(k).getNodeName().equalsIgnoreCase("c360:SalesOrder")) {
                                String POSLOGSalesOrderNo = returnChild.item(k).getFirstChild().getNodeValue();
                                SalesOrderNo = POSLOGSalesOrderNo.substring(2, 12);
                                String SalesOrderNum = POSLOGSalesOrderNo.substring(0, 2);
                                if (SalesOrderNum.equalsIgnoreCase("HD") || (SalesOrderNum.equalsIgnoreCase("SV")) || (SalesOrderNum.equalsIgnoreCase("CR")) || (SalesOrderNum.equalsIgnoreCase("CW"))) {
                                    if (!prevSalesOrder.equals(SalesOrderNo)) {

                                        IDocEl = outdoc.createElement("IDOC");
                                        ORDERS05.appendChild(createIDocHeader(POSLOGSalesOrderNo, outdoc, EMPST, IDocEl, StoreID, true, returnChild));
                                        prevSalesOrder = SalesOrderNo;
                                    }
                                    IDocEl.appendChild(createE1EDP01forReturnLineItem(outdoc, returnChild, StoreID));
                                }

                            }
                        }
                    }
                }
            }


        }
    }
}


//end of gift card

这里我正在阅读根节点<Return>,然后检查它是否包含<Tender> ..如果<Tender>存在(显然<bby:SaleTenderType>将存在).. else if { {1}}不存在,则完成其他功能。

我在此行<Tender>

中获得Null指针异常

请提供您宝贵的意见 提前谢谢..

0 个答案:

没有答案