Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:31:38+00:00 2026-06-09T17:31:38+00:00

I have a three classes: First is Person: public class Person { public string

  • 0

I have a three classes:

First is Person:

    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;
    }
}

Second is:

     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;
    }
}

Third is:

   public class Teacher:Person
{
    public int RoomNumber
    {
        get;
        set;
    }

    public override string ToString()
    {
        return base.ToString() + "," + RoomNumber;
    }
}

I have One more class where i just call the data from PeronDB (Class)

    public class Persons
{
     private List<Person> persons = null;

       public void Fill()
    {
        persons = PersonDB.GetPersons();
    }
 }

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.

    public class PersonDB
{
    private const string path = @"..\..\Persons.xml";

    public static List<Person> GetPersons()
    {
        List<Person> persons = new List<Person>();

        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;
    }
   } 

And in the Form Load i am doing:

     Persons personList = null;

        private void FillPersonlstBox()
    {
        Person p;
        listBox1.Items.Clear();
        for (int i = 0; i < 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();
    }

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:31:40+00:00Added an answer on June 9, 2026 at 5:31 pm

    At some point you’ve got to instantiate personList.

    In your code, you can’t handle the Changed event on personList because it is still null.

    So instead of

    Persons personList = null;
    

    Maybe try

    Persons personList = new Persons();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following (simplified) classes: public class Person { public string Id {get;
I have three classes, first: public class Setting which has properties: string ID, string
I have three classes: Generic, CFG, and Evaluator. Here's Generic: class Generic: public virtual
Assuming I have an object Person with long id String firstName String lastName String
I have three class in my app. First extends Activity public class TestProjActivity extends
I have three classes; Classes A and B both reference class C . How
If I have three classes class A class B extends A class C extends
I have three classes organized in following manner. Foo is a template class, Bar
I have three classes with the following associations: class Technician < ActiveRecord::Base has_many :tickets
I have defined three classes: class Animal < ActiveRecord::Base end class Cat < Animal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.