• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

Object Reference not set to an Instance of an Object

CSS.SSD.Request.CaseLoadData[] data1  = new CSS.SSD.Request.CaseLoadData[1];

// XMLRequest test data
data1[0].Action = "UPDATE/CLOSE";
data1[1].Action = "CREATE";

Right when the code gets to data1[0].Action - I get the error message, Object Reference Not Set to an Instance of an Object

Thanks,

Dan
0
danielolorenz
Asked:
danielolorenz
  • 2
  • 2
1 Solution
 
anarki_jimbelCommented:
Not sure what classes are you using, but...

OK, you declare an array of CaseLoadData objects. By the way, the array has just 1 element!
You do not populate it. Of course, calling data1[0].Action will cause a problem because data1[0] is null. I.e., the array element does NOT contain an object.

The next call, data1[1] , will cause System.IndexOutOfRangeException.
0
 
danielolorenzAuthor Commented:
Thanks.  Okay, then what is the correct way to insert UPDATE/CREATE and CLOSE into the data1 array?  Can you give me a code example?

Thanks,

Dan
0
 
anarki_jimbelCommented:
OK. Again, I don't know your classes, how they are used, how are you going to use your array and so on. So, this is just my guess.

Something like:

            CaseLoadData[] data1 = new CaseLoadData[2];
            CaseLoadData a = new CaseLoadData();
            CaseLoadData b = new CaseLoadData();
            a.Action = "UPDATE/CLOSE";
            b.Action = "CREATE";
            data1[0] = a;
            data1[1] = b;

Open in new window


OR (really, this is the same ):
            CaseLoadData[] data1 = new CaseLoadData[2];
            CaseLoadData a = new CaseLoadData();
            CaseLoadData b = new CaseLoadData();
            data1[0] = a;
            data1[1] = b;
            data1[0].Action = "UPDATE/CLOSE";
            data1[1].Action = "CREATE";

Open in new window

0
 
danielolorenzAuthor Commented:
Worked. Very interesting solution.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now