Possible Duplicate:
What is a NullReferenceException in .NET?
I am using bing soap services in my .net web application and I am getting "Object reference not set to an instance of an object." error in the Line 74:
Line 72: geom p=null;
Line 73: string k = input.country + ", " + input.zipCode;
Line 74: x = p.GeocodeAddress(k); // HERE
Line 75: input.lat = x.Latitude;
Line 76: input.lng = x.Longitude;
The class code is as follows:
using thn.GeocodeService;
public class geom
{
public Location GeocodeAddress(string inputAddress)
{
GeocodeRequest geocodeRequest = new GeocodeRequest();
geocodeRequest.Credentials = new GeocodeService.Credentials();
geocodeRequest.Credentials.ApplicationId = "<my bing code>";
geocodeRequest.Query = inputAddress;
GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
if ((geocodeResponse.Results.Length > 0) && (geocodeResponse.Results[0].Locations.Length > 0))
{
return geocodeResponse.Results[0].Locations[0];
}
else
{
return null;
}
}
}
and the calling part is as follows:
user input;
Location x;
geom p=null;
string k = input.country + ", " + input.zipCode;
x = p.GeocodeAddress(k);
input.lat = x.Latitude;
input.lng = x.Longitude;
Now where could i have been wrong? And also i have added the geocode services to my project's service references, so thats not a problem..