【发布时间】:2012-02-24 23:03:49
【问题描述】:
运行以下代码时出现异常。
Public Function getSongs() As Song()
' Dim dir As New DirectoryInfo(Application.ExecutablePath)
Dim dir As New DirectoryInfo(directory)
Dim songsInDir() As Song = Nothing
Dim i As Integer = 0
For Each file As FileInfo In dir.GetFiles()
'only read ".mp3" files
If file.Extension = ".mp3" Then
songsInDir(i) = New Song(file.Name)
i = +i
End If
Next
Return songsInDir
End Function
我在网上遇到错误:
songsInDir(i) = New Song(file.Name)
我得到一个未捕获的异常,它说:
“对象引用未设置为对象的实例。”
歌曲对象有一个:
Public Sub new(By Val filename as String)
... 设置变量并检索文件信息的子程序(此代码有效)
任何帮助将不胜感激!
【问题讨论】:
标签: vb.net arrays class object constructor