title: I want to load the data from XML file and show in the listbox?
body: <p>I have a three classes:</p>
  
  <p>First is Person:</p>
  
  <pre><code>    public class Person
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Email { get; set; }
  
  
  
      public Person()
      {
      }
  
      public override string ToString()
      {
          return FirstName + " " +LastName + "\t" +Email;
      }
  }
  </code></pre>
  
  <p>Second is:</p>
  
  <pre><code>     public class Student:Person
  {
  
      public Student()
      {
      }
      public double AssessmentGrade { get; set; }
      public double AssignmentGrade { get; set; }
  
      public override string ToString()
      {
          return base.ToString() + "," +AssessmentGrade + "," + AssignmentGrade;
      }
  }
  </code></pre>
  
  <p>Third is: </p>
  
  <pre><code>   public class Teacher:Person
  {
      public int RoomNumber
      {
          get;
          set;
      }
  
      public override string ToString()
      {
          return base.ToString() + "," + RoomNumber;
      }
  }
  </code></pre>
  
  <p>I have One more class where i just call the data from PeronDB (Class)</p>
  
  <pre><code>    public class Persons
  {
       private List&lt;Person&gt; persons = null;
  
         public void Fill()
      {
          persons = PersonDB.GetPersons();
      }
   }
  </code></pre>
  
  <p>InPersonDB class I am doing if its Student node then read the data if its Teacher nodes then also reads the data and If it Person it also reads the data.</p>
  
  <pre><code>    public class PersonDB
  {
      private const string path = @"..\..\Persons.xml";
  
      public static List&lt;Person&gt; GetPersons()
      {
          List&lt;Person&gt; persons = new List&lt;Person&gt;();
  
          XmlReaderSettings settings = new XmlReaderSettings();
          settings.IgnoreWhitespace = true;
          settings.IgnoreComments = true;
  
          XmlReader xmlIn = XmlReader.Create(path, settings);
  
          if (xmlIn.ReadToDescendant("Student"))
          {
              do
              {
                  Person person = new Person();
                  Student student = (Student)person;
                  xmlIn.ReadStartElement("Student");
                  student.FirstName = xmlIn.ReadElementContentAsString();
                  student.LastName = xmlIn.ReadElementContentAsString();
                  student.Email = xmlIn.ReadElementContentAsString();
                  student.AssessmentGrade = xmlIn.ReadElementContentAsInt();
                  student.AssignmentGrade = xmlIn.ReadElementContentAsInt();
  
                  persons.Add(student);
              } while (xmlIn.ReadToNextSibling("Student"));
  
          }
  
          else if (xmlIn.ReadToDescendant("Teacher"))
          {
              do
              {
                  Person person = new Person();
                  Teacher teacher = (Teacher)person;
                  xmlIn.ReadStartElement("Teacher");
                  teacher.FirstName = xmlIn.ReadElementContentAsString();
                  teacher.LastName = xmlIn.ReadElementContentAsString();
                  teacher.Email = xmlIn.ReadElementContentAsString();
                  teacher.RoomNumber = xmlIn.ReadElementContentAsInt();
  
                  persons.Add(teacher);
              } while (xmlIn.ReadToNextSibling("Teacher"));
          }
  
          if (xmlIn.ReadToDescendant("Person"))
          {
              do
              {
                  Person person = new Person();
  
                  xmlIn.ReadStartElement("Person");
                  person.FirstName = xmlIn.ReadElementContentAsString();
                  person.LastName = xmlIn.ReadElementContentAsString();
                  person.Email = xmlIn.ReadElementContentAsString();
  
                  persons.Add(person);
              } while (xmlIn.ReadToNextSibling("Person"));
          }
  
  
          xmlIn.Close();
  
          return persons;
      }
     } 
  </code></pre>
  
  <p>And in the Form Load i am doing:</p>
  
  <pre><code>     Persons personList = null;
  
          private void FillPersonlstBox()
      {
          Person p;
          listBox1.Items.Clear();
          for (int i = 0; i &lt; personList.Count; i++)
          {
              p = personList[i];
              listBox1.Items.Add(p.ToString());
          }
      }
  
      private void Load_Click(object sender, EventArgs e)
      {
          personList.Changed += new Persons.ChangeHandler(HandleChange);
          personList.Fill();
          FillPersonlstBox();
      }
  </code></pre>
  
  <p>It show me in ** personList.Changed += new Persons.ChangeHandler(HandleChange); ** this line error.It shows me "Object reference not set to an instance of an object." this error.
  Please guys help me How to fix it?</p>