IndexOutOfBoundsException: Invalid index 0, size is 0 - converting array of addresses into latlng
<p>i am trying to convert an array of addresses into latlng and it gives an error saying out of bounds, however i checked it on my logcat and all of the address are present which means it is not empty. </p>

<p>error : </p>

<pre><code>java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
12-08 12:39:57.160 15521-15521/homeseek.app.android.capstonehomeseek W/System.err:     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
12-08 12:39:57.160 15521-15521/homeseek.app.android.capstonehomeseek W/System.err:     at java.util.ArrayList.get(ArrayList.java:308)
12-08 12:39:57.160 15521-15521/homeseek.app.android.capstonehomeseek W/System.err:     at homeseek.app.android.capstonehomeseek.ListingNearbyResults.getLocationFromAddress(ListingNearbyResults.java:425)
12-08 12:39:57.160 15521-15521/homeseek.app.android.capstonehomeseek W/System.err:     at homeseek.app.android.capstonehomeseek.ListingNearbyResults.jsonDetails(ListingNearbyResults.java:238)
12-08 12:39:57.160 15521-15521/homeseek.app.android.capstonehomeseek W/System.err:     at homeseek.app.android.capstonehomeseek.ListingNearbyResults.access$000(ListingNearbyResults.java:65)
12-08 12:39:57.160 15521-15521/homeseek.app.android.capstonehomeseek W/System.err:     at homeseek.app.android.capstonehomeseek.ListingNearbyResults$1.onResponse(ListingNearbyResults.java:199)
12-08 12:39:57.160 15521-15521/homeseek.app.android.capstonehomeseek W/System.err:     at homeseek.app.android.capstonehomeseek.ListingNearbyResults$1.onResponse(ListingNearbyResults.java:196)
</code></pre>

<p>array values:</p>

<blockquote>
  <p>{"listing":[{"property_id":"1","property_name":"hotd","property_type":"Board
  House","term":"Monthly","city":"Davao","<strong>address</strong>":"<strong>337 monteverde st,
  davao
  city</strong>","lot_area":"","floor_area":"","price":"2000","bedroom":"1","bathroom":"1","host_name":"jords","host_contact_no":"09457642546","host_details":"heeididudbeksdidh","date_listed":"2016-12-06"},{"property_id":"2","property_name":"Don
  Lorenzo
  Residence","property_type":"House","term":"Weekly","city":"Davao","address":<strong>"San
  Lorenzo Village, Puan Davao
  City"</strong>,"lot_area":"","floor_area":"","price":"25000","bedroom":"1","bathroom":"1","host_name":"Glordel
  Capidos","host_contact_no":"09123456789","host_details":"Just contact
  the number above for more
  infos","date_listed":"2016-12-06"},{"property_id":"3","property_name":"sample","property_type":"Board
  House","term":"Monthly","city":"Davao","<strong>address</strong>":"<strong>377 monteverde st,
  davao
  city</strong>","lot_area":"","floor_area":"","price":"2000","bedroom":"2","bathroom":"2","host_name":"jords","host_contact_no":"0910987263","host_details":"sample","date_listed":"2016-12-06"}],"hasData":true}</p>
</blockquote>

<p>here's the part of the code i got directed where the error occured:</p>

<pre><code>public LatLng getLocationFromAddress(Context context,String strAddress) {

        Geocoder coder = new Geocoder(context);
        List&lt;Address&gt; address;
        LatLng p1 = null;

        try {
            address = coder.getFromLocationName(strAddress, 5);
            if (address == null) {
                return null;
            }
            Address location = address.get(0);
            location.getLatitude();
            location.getLongitude();

            p1 = new LatLng(location.getLatitude(), location.getLongitude() );

        } catch (Exception ex) {

            ex.printStackTrace();
        }

        return p1;
    }
</code></pre>

<blockquote>
  <p><strong>Address location = address.get(0);</strong></p>
</blockquote>

<p>this is where i use the method getlocationfromAddress();</p>

<pre><code>if(hasData){
                Toast.makeText(getApplicationContext(), arrayResponse.length() + " properties found.", Toast.LENGTH_SHORT).show();
                for(int x = 0; x &lt; arrayResponse.length(); x++) {
                    JSONObject jsonObject = arrayResponse.getJSONObject(x);
                    property_id[x] = jsonObject.getString("property_id");
                    property_name[x] = jsonObject.getString("property_name");
                    type[x] = jsonObject.getString("property_type");
                    price[x] = jsonObject.getString("price");
                    address[x] = jsonObject.getString("address");

                    LatLng latLng = getLocationFromAddress(this, address[x]);
                    latitude = latLng.latitude;
                    longitude = latLng.longitude;

                    locationA = new Location("point A");

                    locationA.setLatitude(mLat);
                    locationA.setLongitude(mLng);

                    locationB = new Location("point B");

                    locationB.setLatitude(latitude);
                    locationB.setLongitude(longitude);

                    double listingDistance = locationA.distanceTo(locationB) / 1000;
                    distance[x] = Math.round(listingDistance);

                }
</code></pre>

<p>pls help thanks</p>