例外:
Object reference not set to an instance of an object.
代码:
For Each p As Panel In Me.Controls.OfType(Of Panel)()
arr.Add(p.BackColor.ToString())
Me.Controls.Remove(p)
Next
该行:
arr.Add(p.BackColor.ToString())
我该如何解决这个问题?
答案 0 :(得分:3)
你可能宣称arr
是这样的:
Dim arr As List(Of String)
您需要先将变量初始化为List(Of String)
的实例,然后才能使用它。将其更改为:
Dim arr As New List(Of String)