我的課堂看起來像這樣。類內部的空問,空引用異常,C#
public class LogSettings
{
public string attributeName { get; set; }//TODO: change the variable name
public Warnings[] warnings = new Warnings[3];
}
public class Warnings
{
public string typeOfWarning {get; set;}
public bool isAbsolute { get; set; }
public decimal numUpDownValue { get; set; }
public LogSettingActions[] actionItems = new LogSettingActions[10];
}
public class LogSettingActions
{
public string actionItem{ get; set;}
}
但是當我嘗試創建警告實例時,它會拋出NullReference錯誤。
var rows = FindChilds<ctlLogConfigRow>(lvLogConfigTemplate);
foreach (var row in rows)
{
LogSettings instance = new LogSettings();
instance.attributeName = row.GroupHeaderText;
var allWarnings = FindChilds<ctlWarnings>(row);
for (int i = 0; i < allWarnings.Count; i++)
{
instance.warnings[i].typeOfWarning = allWarnings[i].ctlWarningGroupBoxFixedHeader1.Header.ToString();//It throws error here
任何人都可以幫助我嗎?
錯誤在哪裏?什麼線? – jrummell 2012-03-23 18:23:03
哪一行引發異常? 'null'是什麼引用? – svick 2012-03-23 18:23:16
什麼是空? 'instance'? '警告[I]'? 'allWarnings [I]'? 'ctlWarningGroupBoxFixedHeader1'? 'Header'?您需要提供比此更多的信息... – TDaver 2012-03-23 18:23:45