2012-02-24 11 views
0

次のサブVB.netアレイ例外

投げて投げ「オブジェクトのインスタンスに設定されていないオブジェクト参照」を

例外。

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 

は例外がライン上でスローされるすべてのヘルプは

答えて

1

をいただければ幸いです

col(0) = element.SongTitle 
col(1) = element.PlayTime 
col(2) = element.SongFilename 

あなたは、アレイ内の一つの要素を忘れてしまった

Dim col(3) As String 
+2

配列は0バインド、col(3)は3項目です。 – Jesse

+0

が合意しました。私には恥 –

4

Your array declaration is fine.

あなたのFor Eachイテレータは、どこかでヌルオブジェクトを返しています。ループの本体の周りにヌルテストをラップします。

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