2011-03-25 35 views
0

我正在開發一個基於.NET應用程序使用Twitter的API.I正在以下錯誤:獲得空指針異常在Twitter的API消費.NET

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

代碼如下

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()); 

任何人都可以幫助我嗎?

在此先感謝 達曼

+4

您忘記發佈您的代碼。 – 2011-03-25 10:58:01

+0

你在哪裏得到你的NullReferenceException? – 2011-03-25 11:51:28

+0

確認您的閱讀器能夠獲取標識,名稱和樣式。將調用'reader.GetAttribute(「xxx」)''的結果放入一個變量中,並查看內容。 – 2011-03-25 11:52:53

回答

1

nameidstyle標籤,沒有屬性。因此,GetAttribute返回null

2

你給一個關於使用第三方客戶端庫的思想?

這裏有一些免費的替代品

+0

有沒有免費的工具可用? – Daman 2011-03-25 11:25:48