我正试图从youtube的原子提要中获得缩略图。下面是我的代码:
XNamespace atom = "http://www.w3.org/2005/Atom";
XNamespace media = "http://search.yahoo.com/mrss/";
var YTitems = from entry in document.Descendants(atom + "entry")
select new RSSFeed
{
Image = entry.Element(media + "thumbnail").Attribute("url").Value,
Title = entry.Element(atom + "title").Value,
Description = entry.Element(atom + "content").Value
};
YoutubeList.ItemsSource = YTitems.ToList();
但是当尝试加载提要时,我得到这个错误:
NullReferenceException was unhandled by user code
Object reference not set to an instance of an object
没有"Image = entry.element(......"
也可以工作,所以问题可能在那里。(此处为提要示例)
我修复了这个问题:
ImageSRC = entry.Element(media + "group").Element(media + "thumbnail").Attribute("url").Value