2008-09-10 183 views
0

這是我繼承了一個應用程序的代碼段,用戶拿到死亡黃屏:未設置爲一個對象對實例化對象的NullReferenceException?

的一個實例就行

對象引用:

bool l_Success ... 

現在我95%肯定有故障的說法是ref l_Monitor這是非常奇怪的考慮對象實例化前幾行。任何人都有線索爲什麼會發生?請注意,我看到在代碼的其他地方彈出相同的問題。

IDMS.Monitor l_Monitor = new IDMS.Monitor(); 
l_Monitor.LogFile.Product_ID = "SE_WEB_APP"; 

if (m_PermType_RadioButtonList.SelectedIndex == -1) { 
    l_Monitor.LogFile.Log(
     Nortel.IS.IDMS.LogFile.MessageTypes.ERROR, 
     "No permission type selected" 
     ); 
    return; 
} 
bool l_Success = SE.UI.Utilities.GetPermissionList(
    ref l_Monitor, 
    ref m_CPermissions_ListBox, 
    (int)this.ViewState["m_Account_Share_ID"], 
    (m_PermFolders_DropDownList.Enabled) 
     ? m_PermFolders_DropDownList.SelectedItem.Value 
     : "-1", 
    (SE.Types.PermissionType)m_PermType_RadioButtonList.SelectedIndex, 
    (SE.Types.PermissionResource)m_PermResource_RadioButtonList.SelectedIndex); 
+0

另請參見[.NET中的NullReferenceException是什麼?](http://stackoverflow.com/q/4660142/90527) – outis 2012-03-29 01:13:43

回答

1

您確定嘗試在l_Monitor實例上訪問的某個屬性不爲空?

0

臨時爲該(loooooongg)行的所有屬性查詢添加一些變量。運行調試器,檢查值和角落的小錯誤。

0

我傾向於同意其他人;它聽起來像你正在傳遞的參數之一SE.UI.Utilities.GetPermissionList是null,它導致異常。你最好的選擇是啓動調試器,檢查代碼被調用之前的變量。

0

NullReferenceException實際上是在一個catch塊內引發的,所以堆棧跟蹤無法顯示該行代碼,而是停在了調用者處。

這確實是l_Monitor實例的一個屬性。