爲什麼下面粘貼的代碼會拋出一個空引用異常?因爲我似乎無法找出原因。我看不到這是如何給我一個nullref異常
注:文本框有正確的名稱&當我收到異常時它們不是空的。
我的代碼:(我已經強調了與錯誤的行)
txtGuid.BackColor = Color.White
txtName.BackColor = Color.White
If txtGuid.Text <> "" And txtName.Text <> "" Then
Dim name As String = txtName.Text
Dim guid As String = txtGuid.Text
**frmWhitelist.names.Add(name)**
frmWhitelist.guids.Add(guid)
Me.Close()
Else
If txtGuid.Text = "" Then
txtGuid.BackColor = Color.Red
End If
If txtName.Text = "" Then
txtName.BackColor = Color.Red
End If
lblError.Text = "Please check your input in the red-colored fields."
End If
調用堆棧:
> DayZAdminApp.exe!DayZAdminApp.inptBoxWhitelist.btnOk_Click(Object sender, System.EventArgs e) Line 15 + 0x3d bytes Basic
在調試中,在txtGuid.text
和txtName.text
都有文本值我當地人選項卡。
PS:如果這是由於我試圖將項目添加到另一個窗體上的公共var,我該如何解決這個問題?
PPS:本frmWhitelist.names
和frmWhitelist.guids
被宣佈爲:
Public names, guids As List(Of String)
你能告訴我們哪一個有NullReferenceException?您可以使用調試器附帶的 – Kenneth
'frmWhitelist.names.Add(name)'< - 該行輕鬆檢查該行。 – Yorrick
我想然後frmWhitelist或它的名稱集合爲null爲null。它在哪裏創建? – Kenneth