Am getting
System null reference exception:object reference not set to an instsnce of the object
Line 59: **XmlText nameText = xmldoc.CreateTextNode(name.Text);**
Line 60: XmlText locationText = xmldoc.CreateTextNode(location.Text);
Line 61: XmlText emailText = xmldoc.CreateTextNode(email.Text)
Plz help me out frm this..
Well, there are two obvious potential causes:
Either name
is null, or xmldoc
is null. We can't tell which of those is true, but you should be able to.
A NullReferenceException
is what happens when you try to dereference a reference value which turns out to be null. For example:
string x = null;
int length = x.Length; // Bang - NullReferenceException
Jakub wrote: "Just attach a debugger and check the values of name
and xmldoc
."
Personally I'd write a unit test and think about the code instead of leaping in with a debugger. Using a debugger will find the immediate problem, but thinking about the code will lead you to work out why you've got to this situation, and allow you to treat the symptom rather than the cause. Of course, you can think as well as using a debugger, but I've often seen developers use an interactive debugger as a crutch to avoid thinking.
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.