如何解决未设置为对象实例的对象引用 [英] How to solve the object reference not set to an instance of an object
本文介绍了如何解决未设置为对象实例的对象引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何解决以下错误:
我正在使用MDI表格
这是我尝试的:
How to solve the below error:
I'm using MDI Form
This is what i try:
public static FinancialYear CurrentFinancialYear
{
get
{
return currentFinancialYear;
}
set
{
currentFinancialYear = value;
bool enableState = (value == null ? false : true);
ToolStripItemCollection items = MDIForm.toolStrip1.Items;
string name;
foreach (ToolStripItem toolStripItem in items)
{
name = toolStripItem.Name.ToLower();
if (!(name.Contains("Calculator") || name.Contains("configuration")))
{
toolStripItem.Enabled = enableState;
}
}
}
}
我发现了这个错误:
I'm geting this error:
An unhandled exception of type 'System.NullReferenceException' occurred in Billing Software.exe
Additional information: Object reference not set to an instance of an object.
我的尝试:
如何在c#windows application
What I have tried:
How to solve this error in c# windows application
推荐答案
中解决此错误你必须学习如何使用调试器,精确定位空对象,并确保它在您尝试使用它之前创建
you have to learn how to use a debugger, pinpoint the null object, and make sure it gets created before you try and use it
这篇关于如何解决未设置为对象实例的对象引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文