Object reference not set to an instance of an object.

A

Anonymous

Hello,

I am loading a simple rss file via the XmlTextReader
and getting the following error:

Object reference not set to an instance of an object.

Here is the code which I use:

CheckRSS("http://www.rubyxml.com/index.rb/rss")


private function CheckRSS(byval strRSS as string)
Dim reader as new XmlTextReader(strRSS)
Dim xmlDoc as new XmlDocument

Try
xmlDoc.Load(strRSS)
Catch ex As Exception
Response.Write("ERR in Rss File:" & strRSS
& "<br>")
Response.Write("Err: RSS File:" & ex.Message
& "<br>")
Exit Function
End Try

' load only the item nodes
Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")

For Each node As XmlNode In nodes
Try
Dim strPostTitle as string = node
("title").InnerXml
Dim strPost as string = node
("description").InnerXml
Dim strPostURL as string = node
("link").InnerXml
Dim strPostDate as string = node
("pubDate").InnerXml

response.write(strPostTitle & "<br>")
Catch ex As Exception
Response.Write("ERR in loading nodes: " &
ex.Message() & "<br>")
Exit Function
End Try
Next
end function

Can somebody tell me whats wrong with my code?

Thanks
 
K

Kevin Spencer

Can somebody tell me whats wrong with my code?

Let me count the ways...

To start with, your business logic and interface code are involved in an
unholy union. Didn't you hear about the Great Divorce that ASP.Net was
intended to provoke, between business logic and interface?

It would also help if you pointed out which ine threw the exception. If
you're going to suppress exceptions with a Try/Catch, you could at least
write the stack trace out so you could see where the exception occurred. The
exception message indicates that your code attempted to reference an object
that was not instantiated (Nothing). You didn't post ALL the code you used.
Are you sure the exception came from this block of code, or the calling
code? The reason I ask is that you have defined a function that returns a
string, but if an exception occurs, it calls "Exit Function" which returns
Nothing. If the calling code tried to treat Nothing like a string, that
would throw that particular exception.

Other than that, there are severl places where you might have referenced a
null object (Nothing, for you programmers from Rio Linda), but didn't check
for Nothing prior to the reference, so it could be any of those places.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top