[英]Can't figure out why I'm getting the error, “Object reference not set to an instance of an object”
The block of code where I am getting this is, 我得到的代码块是,
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
The line, "channel.keywords.Add(kw)" is where the error comes up. 出现错误的地方是“ channel.keywords.Add(kw)”行。 I've used this technique dozens of time without a problem, and this seems analogous to every other time I've used it yet I keep getting this exception.
我已经数十次使用该技术了,没有出现任何问题,这似乎与我使用该技术的其他时间类似,但我不断收到此异常。 Can't figure out why.
不知道为什么。
It looks like your SimpleChannel
constructor isn't initializing the keywords
collection. 看来您的
SimpleChannel
构造函数没有初始化keywords
集合。 Make sure the constructor is actually creating an instance of keywords
(ie: keywords = new List(Of String)
or whatever is appropriate). 确保构造函数实际上正在创建
keywords
的实例(即: keywords = new List(Of String)
或其他合适的方法)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.