【问题标题】:Null reference exception unhandled in my program我的程序中未处理的空引用异常
【发布时间】:2012-06-19 08:25:46
【问题描述】:

我在运行代码时收到错误消息“Null reference exception was unhandled”和“Object reference not set to an instance of the object”。 p>

堆栈跟踪

>   Excel1.exe!Excel1.Program.GetAllTemplateNames(string strParam, string strRetVal) Line 121   C#
    Excel1.exe!Excel1.Program.ProcessInput(string strRetVal, string strFunctionName, string strParam1, string strParam2, string strParam3, string strParam4, Excel1.MWMClient.MWMServiceProxy.TemplateData tData, Excel1.MWMClient.MWMServiceProxy.TaskInstance tInstance, int tID) Line 77 + 0x23 bytes    C#
    Excel1.exe!Excel1.Program.Main(string[] args) Line 66 + 0x20 bytes  C#

【问题讨论】:

  • 能否请您提供该行(来自堆栈跟踪或使用调试器)? - 调试应该是一件微不足道的事情 - 但是在没有任何线索的情况下以人类的身份阅读和解释所有代码? ...
  • 谢谢,但是 Linie 121 对应于哪一段代码? - 是的,我知道我很懒,我只是不想自己数 121 行,而你可以做一个简单的 -
  • 这一行列表 templateData = templateClient.GetAllTemplate(siteID).ToList();你可以在switch语句结束后的第一个方法中找到这一行:)
  • 为什么要在 for 循环中创建具有相同值的新 tDatatInstance 实例?为什么不创建一个并重复使用?

标签: c# .net


【解决方案1】:

看起来您没有在使用 taskClienttemplateClient 之前对其进行初始化。我没有看到对您的 TemplateImpl()TaskImpl() 进行初始化的任何调用。

【讨论】:

  • 我在哪里以及如何初始化它们?你能指导我吗?
  • 就像你在我提到的方法中一样,templateClient = new Excel1.MW... 只需在 Main 方法中调用这些方法,也许就在 for 循环之前。
  • 亲爱的朋友,你能说得清楚一点吗?我无法理解你。一些代码可能会有所帮助。
  • @user1463269 在Main 方法中的for 循环之前尝试TemplateImpl(); TaskImpl();
猜你喜欢
  • 2013-12-25
  • 2014-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多