Click here to Skip to main content
15,915,603 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have created a windows app in c# it loads a web page from a site that contains image. there is a button at the side of the app. when i click on the button it calls a method which get the div tag of in which the image exists and save it as bmp on local drive. but when i click on the button it gives the following error.

Object reference not set to an instance of an object.

C#
if (web != null)
{
    HtmlElement elems = web.Document.GetElementById("recaptcha_image")
}

please tell me what i need to do.
Posted
Updated 23-Feb-12 11:36am
v3

You must also check for Document to be not null:
C#
if (web != null)
{
    if (web.Document != null)
    {
        HtmlElement elems = web.Document.GetElementById("recaptcha_image")
    }
}
 
Share this answer
 
I do not know which line you have the exception thrown but you shoud use the magic tool called: Debugger. Put a breakpoint to your if statement check the value of web and elems values. One of them should be null because of that you get that exception. If you have the exception on elems this means that there is no control named "recaptcha_image".

What does object reference not set to an instant of an object mean?[^]

Good luck,
OI
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900