简体   繁体   English

你调用的对象是空的

[英]Object reference not set to an instance of an object

Hello am calling from a class to test my product however i keep getting this error: "Object reference not set to an instance of an object." 您好,我从一个类中调用来测试我的产品,但是我不断收到此错误:“对象引用未设置为对象的实例。”

Testing: 测试:

global::OfficeSystem.Employees employees = new OfficeSystem.Employees();

employees.Delete(Convert.ToInt64("17")); <--- Primary Key
employees.GetEmployeeByOfficeID(Convert.ToInt64("6"));

What is the problem here? 这里有什么问题?

It sounds like for what ever reason you are not instantiating your object. 听起来无论出于什么原因您都没有实例化对象。 I suggest run you code in debug and add a watch on employees to make sure its not zero. 我建议您在调试中运行代码,并在员工上添加监视以确保其不为零。 Hope that helps. 希望能有所帮助。

This simply means you are using an object that is null . 这仅表示您正在使用null的对象。 Accessing a member on null is never valid. 访问null的成员永远是无效的。

I'm not sure which line is causing the error. 我不确定是哪条线引起了错误。 Is it the one that says "Primary Key"? 是说“主键”的那个吗? If so, could employees be null ? 如果是这样,员工是否可以为null It should be extremely trivial to find out using the debugger. 找出使用调试器应该非常简单。

If needed, check for null before using the object to prevent this error. 如果需要,请在使用该对象之前检查是否为null ,以防止出现此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM