Indexout of bound exception
<p>I am trying to use Geocoder for getting a location by passing latitude and longitude.  But I always get an array size of zero and the error <code>indexoutofboundexception index 0 size 0</code>.</p>

<p>I tried with different longitude and latitude values.</p>

<pre><code>    btnShowLocation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // create class object
                gps = new GPSTracker(MainActivity.this);

                // check if GPS enabled
                if (gps.canGetLocation()) {

                    double latitude = gps.getLatitude();
                    double longitude = gps.getLongitude();


                    List&lt;Address&gt; address;

                    Geocoder gcd = new Geocoder(getBaseContext(), Locale
                            .getDefault());

                    try {
                        address = gcd.getFromLocation(latitude, longitude, 1);
                        if (address != null &amp;&amp; address.size() &gt;= 0) {
                            loc = address.get(0).getAdminArea();

                            Toast.makeText(
                                    getApplicationContext(),
                                    "Your Location is - \nLat: " + latitude
                                            + "\nLong: " + longitude + "\nLocation: "
                                            + loc, Toast.LENGTH_LONG).show();

                        } else
                            Toast.makeText(getApplicationContext(), "no data",
                                    Toast.LENGTH_LONG).show();

                        // System.out.println("size of ade " + address.size());
                        // System.out.println(address.get(0).getLocality());
                        // loc = address.get(0).getLocality();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    // \n is for new line
//                  Toast.makeText(
//                          getApplicationContext(),
//                          "Your Location is - \nLat: " + latitude
//                                  + "\nLong: " + longitude + "\nLocation: "
//                                  + loc, Toast.LENGTH_LONG).show();
                } else {
                    // can't get location
                    // GPS or Network is not enabled
                    // Ask user to enable GPS/network in settings
                    gps.showSettingsAlert();
                }

            }
        });
</code></pre>

<p>here is the stack trace</p>

<pre><code>03-26 14:01:06.592: E/AndroidRuntime(11006): FATAL EXCEPTION: main
03-26 14:01:06.592: E/AndroidRuntime(11006): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
03-26 14:01:06.592: E/AndroidRuntime(11006):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at java.util.ArrayList.get(ArrayList.java:304)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at com.example.gpstracker.MainActivity$1.onClick(MainActivity.java:54)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at android.view.View.performClick(View.java:4204)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at android.view.View$PerformClick.run(View.java:17355)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at android.os.Handler.handleCallback(Handler.java:725)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at android.os.Looper.loop(Looper.java:137)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at android.app.ActivityThread.main(ActivityThread.java:5041)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at java.lang.reflect.Method.invokeNative(Native Method)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at java.lang.reflect.Method.invoke(Method.java:511)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-26 14:01:06.592: E/AndroidRuntime(11006):    at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>What is my mistake?  Thanks.        </p>
