对象数组的Nullpointer异常

时间:2017-06-14 14:13:35

标签: java arrays

我写下面的代码拆分一个String并将其插入一个Object Array。但是,

我在下面的行中得到空指针异常。你能告诉我我的代码有什么问题吗?提前致谢

                   nDLs[i].setDisplayName(entrySplit[1]);

代码:

    public class JsonResponse {

         public static void main(String[] args) {

              String response = "eclac-allfocalpoints@un1.org:ECLAC-All Focal Points|testgrp-icc@un.org:TestGRP-ICC|unon-ictsalerts@un.org:UNON-ICTSAlerts|oict-oict-globalvtc@un87.org:OICT-Focal Points All|";
                NodeDLList nDLList = new NodeDLList();



                System.out.println("RESPONSE::::: " + response);

                String split[] = response.split("\\|");

                NodeDLs[] nDLs = new NodeDLs[split.length];

                for (int i = 0; i < split.length; i++) {

                    String entry = split[i];

                    String entrySplit[] = entry.split("\\:");


                       nDLs[i].setDisplayName(entrySplit[1]);
                       nDLs[i].setPrimaryEmail(entrySplit[0]);

                }

                System.out.println("Complete response in Node List Object ::::: " + nDLs);

                nDLList.setdistributionLists(nDLs);

                System.out.println(nDLList);


    }
    }

NodeDLList.java

    public class NodeDLList {



        NodeDLs[] distributionLists = null;



        public NodeDLs[] getdistributionLists() {
            return distributionLists;
        }

        public void setdistributionLists(NodeDLs[] distributionLists) {
            this.distributionLists = distributionLists;
        }


    }

NodeDLs.java

    public class NodeDLs {

        String primaryEmail = null;

        String displayName = null;

        public String getPrimaryEmail() {
            return primaryEmail;
        }

        public void setPrimaryEmail(String primaryEmail) {
            this.primaryEmail = primaryEmail;
        }

        public String getDisplayName() {
            return displayName;
        }

        public void setDisplayName(String displayName) {
            this.displayName = displayName;
        }

0 个答案:

没有答案