Saturday, March 24, 2012

System.Nullreference Exception

i have written the following code to call a method in a class like

in the aspx.cs page
List<string> surls = new List<string>();

Cweb.GetMainUrls(document,ref surls);
Response.Write(surls);

in the Cweb Class page the coding is like

public static void GetMainUrls(Htmldocument doc,ref List<string> urls)
{
//Some functionalities
}

i get the following error when i run the application like

System.NullReference Exception
object reference not set to an instance

so because of this error my method is not getting called from the class and hence no result

can anyone help me out in finding like why my method was not called

i google through several sites and found that
this may be due to the fact that the "surls" are null and hence the method was not called
i dont follow these sequence

so anybody plz help me on this regard
thanks
Rama

System.NullReference Exception means you have referred an object, while this object is not instantialized.
object reference not set to an instance"this may be due to the fact that the "surls" are null and hence the method was not called " --> i think it's probablely because of that. So, set a break point there and debug. then see what the value of urls is. (well, response.write maybe a easier way to do that)

Hope my suggestion helps :)

0 comments:

Post a Comment