以下子投掷
"对象引用未设置为对象的实例。"
异常。
For Each element As Song In modFiles.getSongs()
Dim col(2) As String
Dim item As ListViewItem
col(0) = element.SongTitle
col(1) = element.PlayTime
col(2) = element.SongFilename
item = New ListViewItem(col)
setList.Items.Add(item)
Next
在行
上抛出异常col(0) = element.SongTitle
col(1) = element.PlayTime
col(2) = element.SongFilename
任何帮助将不胜感激
答案 0 :(得分:4)
Your array declaration is fine.
您的For Each
迭代器正在某处返回一个null对象。在循环体周围包裹一个空测试。
For Each element As Song In modFiles.getSongs()
If element IsNot Nothing Then
Dim col(2) As String
Dim item As ListViewItem
col(0) = element.SongTitle
col(1) = element.PlayTime
col(2) = element.SongFilename
item = New ListViewItem(col)
setList.Items.Add(item)
End If
Next
答案 1 :(得分:1)
你忘记了数组中的一个元素
Dim col(3) As String