首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

报错 object reference not set to an instance of an object,是什么原因啊该如何处理

2012-12-25 
报错 object reference not set to an instance of an object,是什么原因啊class Customer{......public b

报错 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一个
[其他解释]
看不懂
[其他解释]
是否重新启动一下计算机

热点排行