for (int i = 0; i < parts.Count; i++)
{
if (!((part)parts[i]).deleteUsed)
((part)parts[i]).hints = ((TextBox)partsView.Rows[i].Cells[4].FindControl("textBox")).Text;
((part)parts[i]).PartsWaiting = ((TextBox)partsView.Rows[i].Cells[5].FindControl("textBox1")).Text;
}
System.NullReferenceException: Object reference not set to an instance of an object.
Im getting this error for some reason, don’t seem to figure out where I’m going wrong.
Your problem is partly due to multiple chained deferences e.g.
and if one of those methods returns null, you can’t easily identify what’s going on.
Unless you’re very sure of what you’re doing, I would split the above into either:
NullPtrExceptionupon resolving a null. Again, your offending line will become apparent immediately.You’ll note that the above isn’t particular to your immediate problem. Rather it’s a useful practise when you can’t be sure that chaining methods won’t return null at some stage.