-1

例外:

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())


我该如何解决这个问题?

4

1 回答 1

3

您可能声明arr了这样的内容:

Dim arr As List(Of String)

您需要先将变量初始化为 的实例,List(Of String)然后才能使用它。将其更改为:

Dim arr As New List(Of String)
于 2012-06-20T19:31:21.423 回答