我正在尝试使用属于指定唯一编号的其他额外信息来获取唯一编号,但它给出了此错误“对象引用未设置为对象的实例。”。我创建了这个类,当我运行时,它只获取唯一并显示它,但它不会获取属于唯一编号的其他值。我搜索了很多例子,但我不能帮助解决这个问题。
这是我的.cs
public Advertentie GetDetails(string unieknummer)
{
XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "root";
xRoot.IsNullable = true;
XmlSerializer deserializer = new XmlSerializer(typeof(Advertentie), xRoot);
StreamReader reader = new StreamReader("C:\\Users\\Gabriel\\documents\\visual studio 2013\\Projects\\ADadvertisement\\ADadvertisement\\Xml\\advertenties.xml");
Advertentie rootObj = (Advertentie)deserializer.Deserialize(reader);
rootObj.Unieknummer = unieknummer;
return rootObj;
}
和我的Page_load()
var obj = new XMLHelper();
Advertentie adv = obj.GetDetails(Request.QueryString["unieknummer"]);
lblTopModel.Text = adv.Unieknummer; //(this one works fine, it show the unique number)
lblTopMerk.Text = Convert.ToString(adv.Laatstemutatie);//(this one doesn't show anything)
lblModel.Text = adv.Auto.Model; //(this one gives me the error Object reference no set to an instance of an object)