[英]c# Object reference not set to an instance of an object
信息路径中的错误:
Object 引用未设置为 object 的实例。 在 Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent) 在 Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent) 的 InfoPathFormTemplate5.FormCode.CTRL407_5_Clicked(Object sender, ClickedEventArgs e)
VB2005 中的错误:Object 引用未设置为 object 的实例。 用户代码未处理 System.NullReferenceException 消息="对象引用未设置为 object 的实例。" Source="InfoPathFormTemplate5" StackTrace: 在 InfoPathFormTemplate5.FormCode.CTRL407_5_Clicked(Object sender, ClickedEventArgs e) 在 C:\Documents and Settings\pebabczu\Desktop\IntakeForm Copy\InfoPathFormTemplate5\FormCode.cs:line 206 在 Microsoft.Office.InfoPath。 Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent) 上的 Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
代码:
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;
我不明白...刚进入 C# 我做错了什么。?
好吧,您正在取消引用原来是 null 的东西。
很难确切地说出您发布的代码中哪一行有问题,但您应该查看第 206 行。我强烈怀疑SelectSingleNode
正在为您的 XPath 表达式之一返回null
- 然后您尝试访问Value
属性,这导致了异常。
因此,您需要:
在实例化之前正在使用某些东西,或者是null
- xnMyForm
实例化了吗? 然后进一步检查所有其他代码路径以确定元素是否为null
或返回此类。
xnMyForm
是null
,或者您正在尝试 select 文档中不存在的节点(使用SelectSingleNode
)并且在返回的null
上调用.Value
很可能您的 SelectSingleNode() 调用之一会返回 null,因此您不能将 a.Value 去掉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.