我正在開發一個基於.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());
任何人都可以幫助我嗎?
在此先感謝 達曼
您忘記發佈您的代碼。 – 2011-03-25 10:58:01
你在哪裏得到你的NullReferenceException? – 2011-03-25 11:51:28
確認您的閱讀器能夠獲取標識,名稱和樣式。將調用'reader.GetAttribute(「xxx」)''的結果放入一個變量中,並查看內容。 – 2011-03-25 11:52:53