RSS阅读器错误-NullReferenceException [英] RSS Reader Error - NullReferenceException

查看:107
本文介绍了RSS阅读器错误-NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imports System.Xml
Imports System.Xml.XPath

Public Class FormRSS

    Private mRssUrl As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        mRssUrl = String.Empty

    End Sub

    Private Sub tsRssGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsRssGo.Click

                'Set RSS Feed URL
                mRssUrl = "http://news.google.co.kr/news?pz=1&cf=all&ned=kr&hl=ko&output=rss"
                'ListView Clear
                tvwRss.Nodes.Clear()
                'Create New XMLDocument Variable
                Dim doc As New XmlDocument()
                Try
                    'Load RSS from RSS URL
                    doc.Load(mRssUrl)
                Catch ex1 As Exception
                    'Showin Error Msg
                    MessageBox.Show(ex1.Message)
                    Return
                End Try
                Dim navigator As XPathNavigator = doc.CreateNavigator()
                Try
                    'Get Post Title form RSS
                    Dim nodes As XPathNodeIterator = navigator.Select("/rss/channel/item/title")
                    While nodes.MoveNext
                        Dim node As XPathNavigator = nodes.Current
                        Dim tmp As String = node.Value.Trim()
                        tmp = tmp.Replace(ControlChars.CrLf, "")
                        tmp = tmp.Replace(ControlChars.Lf, "")
                        tmp = tmp.Replace(ControlChars.Cr, "")
                        tmp = tmp.Replace(ControlChars.FormFeed, "")
                        tmp = tmp.Replace(ControlChars.NewLine, "")
                        'Post Title add to ListView
                        tvwRss.Nodes.Add(tmp)
                    End While
                    Dim position As Integer = 0
                    ' Get the links from the RSS feed
                    Dim nodesLink As XPathNodeIterator = navigator.Select("/rss/channel/item/link")
                    While nodesLink.MoveNext
                        Dim node As XPathNavigator = nodesLink.Current
                        Dim tmp As String = node.Value.Trim()
                        tmp = tmp.Replace(ControlChars.CrLf, "")
                        tmp = tmp.Replace(ControlChars.Lf, "")
                        tmp = tmp.Replace(ControlChars.Cr, "")
                        tmp = tmp.Replace(ControlChars.FormFeed, "")
                        tmp = tmp.Replace(ControlChars.NewLine, "")
                        ' Child Node Add to Parent Nodes
                        tvwRss.Nodes(position).Nodes.Add(tmp)
                        PostBody(position) = tmp   '<----   System.NullReferenceException   Error!!!
                        position += 1
                    End While
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Load Fail")
                End Try
            Catch ex2 As Exception
                MessageBox.Show(ex2.ToString(), "Initialization Fail")
            End Try
        End If
    End Sub



这是RSS阅读器代码的一部分.

在上面的代码中,`PostBody(position)= tmp`部分出现错误.

到底是怎么了?

我不知道. :confused:help



This is Part of an RSS reader code.

In the code above, `PostBody (position) = tmp` Error in part.

What the hell is wrong with it?

I do not know. :confused: help

推荐答案

它告诉您PostBody为空.我假设它是一个迭代器,或者PostBody(position)处的项目为null-换句话说,您尚未在此位置创建实例.试试
It''s telling you that PostBody is null. I assume it''s meant to be an iterator or that the item at PostBody(position) is null - in other words, you haven''t created an instance at this position. Try
PostBody(position) = New whatever this is meant to represent here.


这篇关于RSS阅读器错误-NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆