Click to See Complete Forum and Search --> : Error - NullReferenceException


draghuna
February 22nd, 2006, 12:22 PM
the code given below throws me a NULReferenceException error, can someone help me on this. The variable cFile is assigned from outside. I can see the list thats been accessed from the xml file but for some reason when I try to assign the productNode.Name it throws the error. Any Help is certainly appreciated. Thanks

CODE:

public class Product

{

public string Name;

public string abbrion;

}


public class Config


{

public string cFile;


public Product[] getProducts()

{


XmlDocument xdoc = new XmlDocument();

xdoc.Load(cFile);

XmlNodeList pnode = xdoc.GetElementsByTagName("Prod");

Product [] productNode = new Product [pnode.Count];

for(int i=0; i < pnode.Count; i++)

{

productNode[i].Name = pnode[i].Attributes["ID"].Value.ToString();

productNode[i].abbr = pnode[i].Attributes["Description"].Value.ToString();


}

return productNode;

}

DD

jhammer
February 22nd, 2006, 12:41 PM
Product [] productNode = new Product [pnode.Count];

for(int i=0; i < pnode.Count; i++)

{

productNode[i] = new Product();
productNode[i].Name = pnode[i].Attributes["ID"].Value.ToString();

productNode[i].abbr = pnode[i].Attributes["Description"].Value.ToString();


}

draghuna
February 22nd, 2006, 01:26 PM
I knew it was a silly mistake but did not know it was this silly :). I am new to OO, thats why. Thanks for your help. I certainly appreciate it.

DD