读书人

报错 object reference not set to an

发布时间: 2012-12-30 10:43:15 作者: rapoo

报错 object reference not set to an instance of an object,是什么原因啊
class Customer
{
......
public bool save()
{
if (this.Id == -1)
{
int customerId = DataManager.addCustomer(this);//此处报错
if (customerId == -1) return false;
else
{
this.Id = customerId;
return true;
}
}
else
{
DataManager.UpdataCustomer(this);
return true;
}
}
}

static class DataManager
{
static public int addCustomer(Customer customer)
{
if (getCustomerId(customer.Name)!=-1) return -1;
tb_Customer tb_customer = new tb_Customer();
tb_customer.Id = customer.Id;
tb_customer.Name = customer.Name;
tb_customer.Password = customer.Password;
tb_customer.PhoneNumber = customer.PhoneNumber;
dataContext.tb_Customer.InsertOnSubmit(tb_customer);
return getCustomerId(customer.Name);
}
}
[解决办法]
对象未实例化,不能是this,new一个

读书人网 >C++ Builder

热点推荐