我一直在绞尽脑汁(不难)试图找出这个例外。我有一个显示用户信息的表单。当我设置断点并单步执行代码时。方法调用返回对象(在即时窗口中检查),但是当我将用户属性分配给标签时,就会发生这种情况。
这是我的代码:
public Form2()
{
UserInfo user = FileAccess.UserInfoFromXML();
// All the members of user exist.
label1.Text = "Screen Name: " + user.ScreenName; //This is throwing an Null Reference exception the UserInfo is not null
label2.Text = "Full Name: "+ user.FirstName + " " + user.LastName;
label3.Text = "Address: " + user.StreetAddress + " " + user.City + " " + user.State + " " + user.Zip;
label4.Text = "Email Address: " + user.email;
label5.Text = "Date Of Birth: " + user.DateOfBirth;
label6.Text = "Start Date: " + user.StartDate;
DateTime dt = DateTime.Parse( user.StartDate );
dt.AddDays( 30 );
label7.Text = "End Date: " + dt.ToShortDateString();
}
有任何想法吗?谢谢你