1

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..

Community
  • 1
  • 1
raj25
  • 11
  • 1
  • Welcome to Stack Overflow! Almost all cases of NullReferenceException are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Dec 22 '12 at 05:28
  • Seriously? Your code is basically `geom p=null;x = p.GeocodeAddress(k);`. It's the same as doing `x = null.GeocodeAddress(k);`. That has nothing at all to do with Bing maps! – John Saunders Dec 22 '12 at 05:30

1 Answers1

0

You need create a new instance of the geom class. You aren't instantiating p. p is null. Try

geom p = new geom();

dustyhoppe
  • 1,783
  • 16
  • 20