我有这样的事情:
class MyTask
{
public MyTask(int id)
{
Id = id;
IsBusy = false;
Document = new HtmlDocument();
}
public HtmlDocument Document { get; set; }
public int Id { get; set; }
public bool IsBusy { get; set; }
}
class Program
{
public static void Main()
{
var task = new MyTask(1);
task.Document.LoadHtml("http://urltomysite");
if (task.Document.DocumentNode.SelectNodes("//span[@class='some-class']").Count == 0)
{
task.IsBusy = false;
return;
}
}
}
现在,当我启动我的程序时,它会在语句上抛出一个错误if
,说Object reference not set to an instance of an object.
. 为什么它不加载我的页面?我在这里做错了什么?