Get the error: "Object reference not set to an instance of an object"

Peter Kiers
Peter Kiers used Ask the Experts™
on
Hi

I have this code:
        private void bbGetHtml_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            HtmlAgilityPack.HtmlDocument page = new HtmlWeb().Load("https://www.xxx.nl/search/process_result.phtml?mypref_search_id=0");
            var pageLinks = page.DocumentNode.SelectNodes("//class[@class='mtcMemberNotGreylisted']//a");
            foreach (var link in pageLinks)
            {
                txtResult.Text = link.Attributes["title"].Value;
            }
        }

Open in new window


But i get the error at the Foreach-line: "Object reference not set to an instance of an object"
What does this mean and who can help me?

Greetings, Peter Kiers
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance programmer / Consultant
Commented:
You need to check you have any pageLinks:
        private void bbGetHtml_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            HtmlAgilityPack.HtmlDocument page = new HtmlWeb().Load("https://www.xxx.nl/search/process_result.phtml?mypref_search_id=0");
            var pageLinks = page.DocumentNode.SelectNodes("//class[@class='mtcMemberNotGreylisted']//a");
if(pageLinks != null)
{
            foreach (var link in pageLinks)
            {
                txtResult.Text = link.Attributes["title"].Value;
            }
}
        }

Open in new window

Peter KiersOperator

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial