-3

I get this error:

System.IndexOutOfRangeException: Index was outside the bounds of the array.

when running this code:

foreach(var row in data)
{
     string strAddr = row.ADDRESS1 + "," + row.CITY + "," + row.ST;

     GoogleMapsDll.GeoResponse myCoordenadas = new GoogleMapsDll.GeoResponse();
     myCoordenadas = GoogleMapsDll.GoogleMaps.GetGeoCodedResults(strAddr);

     string strLat = myCoordenadas.Results[0].Geometry.Location.Lat.ToString();  
     string strLong = myCoordenadas.Results[0].Geometry.Location.Lng.ToString();

     System.Threading.Thread.Sleep(10); 

}

I am not sure exactly what it means or how I might go about fixing it. Any input would be appreciated.

Manish Mishra
  • 12,163
  • 5
  • 35
  • 59
  • 1
    You are not getting any `Results` back from your API call – Habib Oct 02 '14 at 15:31
  • 2
    Try debugging. Also, [try searching](http://stackoverflow.com/search?q=IndexOutOfRangeException) and perhaps there is another question that is similar. – crashmstr Oct 02 '14 at 15:33

1 Answers1

2

It is usually thrown by indexing operators like x[12]. You happen to have that: Results[0]. So it must mean that the array is actually empty, it doesn't even have a zero index. By the way, run your code in a debugger and see where exactly the exception is thrown.

fejesjoco
  • 11,763
  • 3
  • 35
  • 65