Hello,
Quote:
Object Reference not set to an instance of an object
This error occurs when the object you are trying to reference is not present in the heap.
When is an object allocated on the heap???
: Suppose i say:
Class1 c = new Class1();
///Please note that the "new" keyword allocates the object on the heap.
- If i dont say "new" then "Class1" is just a blue print it does not come into realization until i say "new".
- If you simply say:
Class1 c;
and later in your code you say :
c.some_method();///this wont work and an exception will be thrown at this line.
Try out this code:
class Program
{
public void method()
{
Console.WriteLine("hello");
}
static void Main(string[] args)
{
Program p = null;
p.method(); Console.ReadLine();
}
}
();
Console.ReadLine();
}
}
- In your case also the situation may be something similar. So the line where you get an error set a break point(right click that line and set a break point).
- Now hover your the mouse to the object/objects(used in that line) used in places before that line. You will see that the object/objects are null.
- Now reinitialize the objects by using the "new" keyword. This should help. Just a little debugging and the problem should go.
Thanks,
-Rahul