error in Infopath:
Object reference not set to an instance of an object.
at InfoPathFormTemplate5.FormCode.CTRL407_5_Clicked(Object sender, ClickedEventArgs e)
at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)error in VB2005: Object reference not set to an instance of an object.
System.NullReferenceException was unhandled by user code
Message=”Object reference not set to an instance of an object.”
Source=”InfoPathFormTemplate5″
StackTrace:
at InfoPathFormTemplate5.FormCode.CTRL407_5_Clicked(Object sender, ClickedEventArgs e) in C:\Documents and Settings\pebabczu\Desktop\IntakeForm Copy\InfoPathFormTemplate5\FormCode.cs:line 206
at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
Code:
string TeamL = xnMyForm.SelectSingleNode("/my:myFields/my:field149", ns).Value;
string ACC = xnMyForm.SelectSingleNode("/my:myFields/my:Bank", ns).Value;
string remarkmain = xnMyForm.SelectSingleNode("/my:myFields/my:field104", ns).Value;
string RemarkHR = xnMyForm.SelectSingleNode("/my:myFields/my:Remarks1", ns).Value;
string RemarkTL = xnMyForm.SelectSingleNode("/my:myFields/my:field55", ns).Value;
string RemarkIT = xnMyForm.SelectSingleNode("/my:myFields/my:RemarksICT", ns).Value;
string Rmain = "Remarks: " + remarkmain;
string RHR = "Remarks: " + RemarkHR;
string RTL = "Remarks: " + RemarkTL;
string RIT = "Remarks: " + RemarkIT;
I dont get it… Just getting into C# what did I do wrong.?
Well, you’re dereferencing something that turns out to be null.
It’s hard to say exactly which line of code is problematic out of what you posted, but you should look at line 206. I strongly suspect that
SelectSingleNodeis returningnullfor one of your XPath expressions – you’re then trying to access theValueproperty, which is causing the exception.So, you need to: