This discussion is archived
1 Reply Latest reply: Sep 26, 2010 1:21 PM by 791266 RSS

Getting NullPointerException adding an object to an object array - Help!

800668 Newbie
Currently Being Moderated
I am working on a webservice where the request can contain a dynamic array of SingleOwnerRequestNodeDetail objects. I need to read these objects in and sort them according to an orderNbr that is contained in the object.
I am attempting to read these object into a Comparable class and sort them. I am having problems when I try to insert the objects into my object array ComparableBO[]. (See line in bold.) I get the following error: Exception during processing: java.lang.NullPointerException

Any help here would be appreciated. Thanks!

Here's my class:

public class ComparatorBO implements Comparable {

     private SingleOwnerRequestNodeDetail nodeDetailInfo;
     private int orderNbr;
     public SingleOwnerRequestNodeDetail getNodeDetailInfo() {
          return nodeDetailInfo;
     public void setNodeDetailInfo(SingleOwnerRequestNodeDetail nodeDetailInfo) {
          this.nodeDetailInfo = nodeDetailInfo;
     public int getOrderNbr() {
          return Integer.parseInt(nodeDetailInfo.getSingleOwnerRequestOrderNbr());
     public void setOrderNbr (int orderNbr) {
          this.orderNbr = orderNbr;

     public int compareTo(Object anotherNodeDetailInfo)throws ClassCastException {
          if (!(anotherNodeDetailInfo instanceof ComparatorBO))
               throw new ClassCastException ("An single owner request node detail object is expected");
          int anotherNodeDetailOrderNbr = ((ComparatorBO)anotherNodeDetailInfo).getOrderNbr();
          return this.orderNbr - anotherNodeDetailOrderNbr;

Here's the code where I read in the objects and attempt to place them in the comparableBO[]

ComparatorBO[] comparatorBOArray = null;

comparatorBOArray = new ComparatorBO[requestInfo.length];
          for (int i=0; i < requestInfo.length; i++)
               SingleOwnerRequestNodeDetail nodes = new SingleOwnerRequestNodeDetail();
               ComparatorBO comparatorBO = new ComparatorBO();