2009-12-01 64 views
3

我已經編寫並測試了一個WinForms應用程序,並且在我的機器上一切都正常工作(我知道這是陳詞濫調)。當我創建了一個安裝項目和安裝了一個同事的機器上,他收到以下消息:異常處理幫助

************** Exception Text ************** 
    System.IndexOutOfRangeException: There is no row at position 0. 
    at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) 
    at System.Data.RBTree`1.get_Item(Int32 index) 
    at System.Data.DataRowCollection.get_Item(Int32 index) 
    at MyApp.MainForm.MainForm_Load(Object sender, EventArgs e) 
    at System.Windows.Forms.Form.OnLoad(EventArgs e) 
    at System.Windows.Forms.Form.OnCreateControl() 
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 
    at System.Windows.Forms.Control.CreateControl() 
    at System.Windows.Forms.Control.WmShowWindow(Message& m) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
    at System.Windows.Forms.ContainerControl.WndProc(Message& m) 
    at System.Windows.Forms.Form.WmShowWindow(Message& m) 
    at System.Windows.Forms.Form.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

我承認我是一個新手,當涉及到處理這樣的一個例外。這段文字對我來說並沒有什麼意義,我不確定調試這種方法的最佳方式,因爲我無法在我的機器上發生錯誤。

任何人都可以告訴問題是什麼,或者建議我調試這個最好的方法嗎?任何幫助是極大的讚賞!

+0

你可以發佈'MyApp.MainForm.MainForm_Load'的代碼嗎? – 2009-12-01 21:51:10

回答

6

顯然,你正在使用一個DataRowCollection對象你的主表單加載事件處理程序,而這個DataRowCollection對象是空的(即不包含行)。表單加載事件處理程序似乎假定它將而不是爲空。

我建議你通過代碼在MainForm_Load的開啓大括號上設置斷點(F9),並通過代碼設置步驟(F10或F11),直至找到代碼嘗試使用DataRowCollection的位置。

1

聽起來像數據的差異 - 你試圖通過一個不存在的索引來訪問節點在樹上......

1

您正在創建一個數據行集合,並使用collection[0]訪問它,而不驗證它是否至少有一個元素開頭。也許你的coleague連接到一個沒有行的空數據存儲?