Daman
Daman

Reputation: 25

Getting Null Pointer Exception in Twitter API consumption in .net

I am developing a .net based application to consume Twitter API.I am getting the following error:

System.NullReferenceException: Object reference not set to an instance of an object

Code is as follows

StringBuilder strB = new StringBuilder();
XmlReader reader = new XmlTextReader("http://twitter.com/statuses/public_timeline.xml");
try
{
    while (reader.ReadToFollowing("user"))
    {
        strB.Append("z: " + reader.GetAttribute("id").ToString());
        strB.Append(" | Y: " + reader.GetAttribute("name").ToString());
        strB.Append(" | style: " + reader.GetAttribute("style").ToString());
     }
}
catch (Exception ex) 
{ 
     Response.Write(ex.ToString()); 
}
finally
{
    reader.Close();
}
Response.Write(strB.ToString());

Can anyone help me?

Thanks in advance Daman

Upvotes: 0

Views: 445

Answers (2)

SLaks
SLaks

Reputation: 888107

name, id, and style are tags, not attributes.
Therefore, GetAttribute returns null.

Upvotes: 1

abhilash
abhilash

Reputation: 5651

Have you given a thought about using a third party client library ?

Here are some of the free alternatives

Upvotes: 2

Related Questions