Object reference not set to an instance of an object

A

andrewcw

( excuse earlier bad post, I was attemptingt to use tab
key which sent message ).

I am using a class genereated by XSD. From data I will
collect I plan to build the object & serialize as XMl
But I cannot yet load the object heirarchy w/o error
an array of diskitem with each having an array of item as
iluustrated below
<qrecord> <!-- root -->
<diskitem ...>
<item ...>
<what ...>
</item>
</diskitem>
<diskitem ...>
<item ...>
<what ...>
</item>
</diskitem>
</qcrecord>

test code looks like this ( Thanks ) :
try
{
qcstate.qcrecord fullQCState = new qcstate.qcrecord();
qcstate.disksetitem dsItemObj = new qcstate.disksetitem();
fullQCState.disksetitem[0]=dsItemObj; // attach a diskitem
object but this ALREADY FAILS

qcstate.item manItem = new qcstate.item();
dsItemObj.item[0]= manItem; // attach an iten object to
diskitem
qcstate.what whatObj = new
qcstate.whatdsItemObj.customer_code="KFC";
whatObj.bookid="foo man"; //
manItem.what=whatObj; // attach the what obj to an item
Object
}
catch ( Exception e)
{
Console.WriteLine(e.Message);
}

// from class file: public class qcrecord {

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute
("disksetitem")]
public disksetitem[] disksetitem;
}
 
M

Mike Bird

When adding objects into an array, you need to new them up. An object array
is simply an array of references which until initialized are nulls. You
can't simply copy to them, you have to give them something to reference.

fullQCState.disksetitem[0]= new qcstate.disksetitem();;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top