I have been racking my brain (not hard to do) trying to figure this exception out. I have a form that display’s user information. When I set breakpoints and step through the code. The method call returns the object (checked in the immediate window) but when I assign the user property to the label is when this occurs.
Here is my code:
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();
}
Any ideas?
Thank You
You’ll have to let the
InitializeComponent()call stay on top of the constructor.This designer-generated method initializes your components so the labels won’t be
nullanymore when you access them.