1
我需要善意簽署任務。我想用htmlaglitypack來計數標籤。我試圖通過使用htmlcollection節點來計數標籤。但得到對象引用未設置爲html集合的實例
"Object reference not set to an instance of an object"
在行foreach條件。他們中的任何一個人能否糾正爲什麼我會這樣的問題?
我的代碼貼在下面:
public void XmlPPC(string rights)
{
int count = 0;
try
{
MessageBox.Show(rights);
using (FileStream fs = File.Open(rights,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(sr);
HtmlNodeCollection right = doc.DocumentNode.SelectNodes("//copyrightLine");
foreach (HtmlNode logan in right)
{
count = count + 1;
MessageBox.Show("cnt" + count.ToString());
}
// snip...
}
}
catch (Exception f)
{
log = log + "\r\n" + f.ToString();
}
}
您確定標籤中存在標籤嗎? – ChrisBint 2013-02-26 12:57:14
請參閱:[什麼是.NET中的NullReferenceException?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) – Default 2013-02-26 13:10:23
是的ChrisBint。標籤退出源文件 – Gan 2013-02-27 05:33:21