Vb.net Can';我不明白为什么我';“我得到了错误,”他说;对象引用未设置为对象的实例;
我得到的代码块是Vb.net Can';我不明白为什么我';“我得到了错误,”他说;对象引用未设置为对象的实例;,vb.net,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.channe
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)”一行就是出现错误的地方。我已经毫无问题地使用了几十次这种技术,这似乎与我使用它的每一次都类似,但我一直得到这个例外。无法找出原因。看起来您的
SimpleChannel
构造函数没有初始化关键字
集合。确保构造函数实际上正在创建关键字的实例(即:关键字=新列表(字符串)
或任何合适的实例)。看起来您的SimpleChannel
构造函数没有初始化关键字
集合。确保构造函数实际上正在创建关键字的实例(即:关键字=新列表(字符串)
或任何适当的内容)。很可能是问题所在。如果OP可以发布SimpleChannel源代码,我可能能够确认它。正确,而且我意识到我在初始化结果时忘记使用New,这是SimpleChannel的列表。非常感谢。很可能是这个问题。如果OP可以发布SimpleChannel源代码,我可能能够确认它。正确,而且我意识到我在初始化结果时忘记使用New,这是SimpleChannel的列表。非常感谢。可以显示SimpleChannel
源代码吗?可以显示SimpleChannel
源代码吗?