无法弄清楚为什么我收到错误,“对象引用未设置为对象的实例”

时间:2012-08-22 18:44:44

标签: vb.net

我得到的代码块是,

 If userID > 0 Then
            Dim lq As New lqDFDataContext
            Dim var = lq.mobile_GetCustomChannels(userID).ToList()
            For Each c In var
                Dim channel As New SimpleChannel
                channel.channelID = c.channelID
                channel.userID = c.userID

                If c.matchTitle = True Then
                    channel.matchBy = "Title"
                End If

                If c.matchTitleAbstract = True Then
                    channel.matchBy = "Title and Abstract"
                End If

                If c.fromMyPage = True Then
                    channel.source = "My Page"
                Else
                    channel.source = "All Journals"
                End If

                   Dim tempKW() As String = c.keywords.Split(",")
                For Each kw As String In tempKW
                    channel.keywords.Add(kw)
                Next

                Dim imageKW As String = c.keywords.Substring(0, c.keywords.IndexOf(" "))
                channel.imageURL = SingleImageSearch(imageKW)


                result.Add(channel)
            Next
        End If

该行," channel.keywords.Add(kw)"是出现错误的地方。我已经使用了这种技术几十次没有问题,这看起来类似于我已经使用它的所有时间但我一直得到这个例外。无法弄清楚原因。

1 个答案:

答案 0 :(得分:1)

您的SimpleChannel构造函数似乎未初始化keywords集合。确保构造函数实际上正在创建keywords的实例(即:keywords = new List(Of String)或任何合适的实例)。