简体   繁体   English

无法弄清楚为什么出现错误“对象引用未设置为对象的实例”

[英]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.

相关问题 你调用的对象是空的。 不知道为什么我得到这个错误 - Object reference not set to an instance of an object. unknown why i'm getting this error 收到“未将对象引用设置为对象实例”错误,不确定原因 - getting an “object reference not set to an instance of an object” error, not sure why 为什么会出现“对象引用未设置为对象实例”的错误? - Why am I getting “Object reference not set to an instance of an object.” error? 我有一个错误,上面写着“对象引用没有设置为对象的实例”。 我是初学者 - I'm having an error which says “Object reference not set to an instance of an object”. I'm a beginner 获取“对象引用未设置为对象实例”的错误..vb - Getting the 'Object reference not set to an instance of an object' error..vb 为什么我的对象引用未设置为 Google Drive Api 中的对象实例。? - Why I am getting Object reference not set to an instance of an object in Google Drive Api.? 我为什么会这样,“对象引用未设置为对象的实例。”但是没有涉及到任何代码行? - Why am I getting, “Object reference not set to an instance of an object.” but no line of code is implicated? “对象引用未设置为对象的实例”:为什么.NET不能显示更多详细信息? - “Object reference not set to an instance of an object”: why can't .NET show more details? 如何解决“对象引用未设置为对象实例”的错误? - How do I resolve “Object reference not set to an instance of an object” error? 如何修复“对象引用未设置为 object 的实例。” 错误? - How can i fix 'Object reference not set to an instance of an object.' error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM