简体   繁体   中英

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 . Accessing a member on null is never valid.

I'm not sure which line is causing the error. Is it the one that says "Primary Key"? If so, could employees be 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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