Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all. the code is:
C#
 public class PersonelInfoAndEmploymentInfo
    {
        public employmentInfo _empinfo{set;get;}
        public PersonelInfo _pinfo { set; get; }
    }
public class PersonelInfo
{
//some fields
}
public class employmentInfo  
{
//some fields
}

//access from a winform
PersonelInfoAndEmploymentInfo person = new PersonelInfoAndEmploymentInfo();
person._empinfo.jobLocation = "asdasd";

//error:Object reference not set to an instance of an object.
Posted
Comments
Richard MacCutchan 28-Jan-14 7:55am    
You have not set _empinfo to anything.

1 solution

SQL
public class PersonelInfoAndEmploymentInfo
    {
        public employmentInfo _empinfo{set;get;}
        public PersonelInfo _pinfo { set; get; }
        public PersonelInfoAndEmploymentInfo()
        {
           _empinfo = new employmentInfo();
           _pinfo   = new PersonelInfo(); 
        }
    }


change your class like this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900