By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,069 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,069 IT Pros & Developers. It's quick & easy.

Object reference not set to an instance of an object

P: n/a
( 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;
}
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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();;

"andrewcw" <an************@boeing.com> wrote in message
news:01****************************@phx.gbl...
( 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;
}

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.