title: geocoder on android show java lang index out of bound exception
body: <p>i tried to make application to convert from latitude and longitude to an address</p>
  
  <p>the problem is geocoder class didnt work and throw an exception</p>
  
  <p>on below i put java class and xml also with log cat</p>
  
  <pre><code>    package com.example.androidfromlocation;
  
  import java.io.IOException;
  import java.util.List;
  import java.util.Locale;
  
  import android.app.Activity;
  import android.location.Address;
  import android.location.Geocoder;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class AndroidFromLocation extends Activity {
  
      double LATITUDE = 37.42233;
      double LONGITUDE = -122.083;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          TextView myLatitude = (TextView)findViewById(R.id.mylatitude);
          TextView myLongitude = (TextView)findViewById(R.id.mylongitude);
          TextView myAddress = (TextView)findViewById(R.id.myaddress);
  
          myLatitude.setText("Latitude: " + String.valueOf(LATITUDE));
          myLongitude.setText("Longitude: " + String.valueOf(LONGITUDE));
  
          Geocoder geocoder = new Geocoder(this);
  
          try {
              List&lt;Address&gt; addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
  
              if(addresses != null) {
                  Address returnedAddress = addresses.get(0);
                  StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
                  for(int i=0; i&lt;returnedAddress.getMaxAddressLineIndex(); i++) {
                      strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
                  }
                  myAddress.setText(strReturnedAddress.toString());
              }
              else{
                  myAddress.setText("No Address returned!");
              }
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              myAddress.setText("Canont get Address!");
          }
  
      }
  }
  </code></pre>
  
  <p>and this the xml file</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".AndroidFromLocation" &gt;
  
   &lt;LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt;
     &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello"/&gt;
     &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Location" android:background="#505050"/&gt;
     &lt;TextView android:id="@+id/mylatitude" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt;
     &lt;TextView android:id="@+id/mylongitude" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt;
     &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Address" android:background="#505050"/&gt;
     &lt;TextView android:id="@+id/myaddress" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt;&lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and also this is the log cat</p>
  
  <pre><code>11-06 07:58:18.439: D/dalvikvm(16360): GC_CONCURRENT freed 86K, 2% free 6208K/6328K, paused 3ms+10ms, total 35ms
  11-06 07:58:18.451: W/EGL_emulation(16360): eglSurfaceAttrib not implemented
  11-06 08:08:23.003: E/Trace(17062): error opening trace file: No such file or directory (2)
  11-06 08:08:23.031: D/AndroidRuntime(17062): Shutting down VM
  11-06 08:08:23.035: W/dalvikvm(17062): threadid=1: thread exiting with uncaught exception (group=0xa6198908)
  11-06 08:08:23.035: E/AndroidRuntime(17062): FATAL EXCEPTION: main
  11-06 08:08:23.035: E/AndroidRuntime(17062): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.azuraakbar.androidfromlocation/com.azuraakbar.androidfromlocation.AndroidFromLocation}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.os.Handler.dispatchMessage(Handler.java:99)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.os.Looper.loop(Looper.java:137)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.ActivityThread.main(ActivityThread.java:5041)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at java.lang.reflect.Method.invokeNative(Native Method)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at java.lang.reflect.Method.invoke(Method.java:511)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at dalvik.system.NativeStart.main(Native Method)
  11-06 08:08:23.035: E/AndroidRuntime(17062): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at java.util.ArrayList.get(ArrayList.java:304)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at com.azuraakbar.androidfromlocation.AndroidFromLocation.onCreate(AndroidFromLocation.java:36)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.Activity.performCreate(Activity.java:5104)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  11-06 08:08:23.035: E/AndroidRuntime(17062):    ... 11 more
  </code></pre>
  
  <p>thanks in advance</p>