title: Filter listview with data from mysql database
body: <p>I am trying to change the <code>private void displayListView()</code> of this tutorial (<a href="http://www.mysamplecode.com/2012/07/android-listview-custom-layout-filter.html" rel="nofollow">http://www.mysamplecode.com/2012/07/android-listview-custom-layout-filter.html</a>) so I can check if it would still work if I get the data from mySql database instead.</p>
  
  <p>Here's the Json Array from my PHP file:</p>
  
  <pre><code>[{"code":"AFG","name":"Afghanistan","continent":"Asia","region":"Southern and Central Asia"},    {"code":"ALB","name":"Albania","continent":"Europe","region":"Southern Europe"},{"code":"DZA","name":"Algeria","continent":"Africa","region":"Northern Africa"},{"code":"ASM","name":"American Samoa","continent":"Oceania","region":"Polynesia"},{"code":"AND","name":"Andorra","continent":"Europe","region":"Southern Europe"},{"code":"AGO","name":"Angola","continent":"Africa","region":"Central Africa"},{"code":"AIA","name":"Anguilla","continent":"North America","region":"Caribbean"}]
  </code></pre>
  
  <p>Here's what I did:</p>
  
  <pre><code>private void displayListView() {
          // Creating volley request obj
          JsonArrayRequest stringRequest = new JsonArrayRequest(url,
                  new Response.Listener&lt;JSONArray&gt;() {
                      @Override
                      public void onResponse(JSONArray response) {
                          // Parsing json
                          for (int i = 0; i &lt; response.length(); i++) {
                              try {
                                  JSONObject obj = response.getJSONObject(i);
                                  Country country = new Country(code, name, continent, region);
                                  country.setCode(obj.getString("code"));
                                  country.setName(obj.getString("name"));
                                  country.setContinent(obj.getString("continent"));
                                  country.setRegion(obj.getString("region"));
  
                                  // adding country to country array
                                  countryList.add(country);
  
                              } catch (JSONException e) {
                                  e.printStackTrace();
                              }
                          }
                      }
                  }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Toast.makeText(MainActivity.this,error.getMessage(),Toast.LENGTH_LONG).show();
  
              }
          });
  
          RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
          queue.add(stringRequest);
  </code></pre>
  
  <p>But I am getting an error:</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  </code></pre>
  
  <p>I am not sure if I am parsing JSON the right way, and I can't figure the error out. Any help will be greatly appreciated.</p>