title: JsonArray error : org.json.JSONException: JSONArray[1] not found
body: <p>I am currently new in Json and faced to a problem. I Searched a lot but could not find an answer to it! </p>
  
  <p>I am getting a list of names from a json url. names can be duplicated in this json file but i only want to keep one record of them to my new array which i called "arr". You can see the code as following: </p>
  
  <pre><code>    JSONArray interests = json.getJSONArray("Interests");
      JSONArray arr = new JSONArray();
      int i = 0;
      int p = 0;
      int e = 0;
  
      for (; i &lt; interests.length(); i++) {
  
          JSONArray items = interests.getJSONObject(i).getJSONArray("items");
          for (int j = 0; j &lt; items.length(); j++) {
              String string = items.getJSONObject(j).getString("authors");
              String[] parts = string.split(",");
              for (int k = parts.length - 1; k &gt;= 0; k--) {
  
                  for (int a = 0; a &lt;= arr.length(); a++) {
  
                      if (arr.length() == 0 || !arr.getJSONObject(a).getString("label").equals(parts[k])) {
                          JSONObject obj = new JSONObject();
                          obj.put("id", p++);
                          // obj.put("value", e++);
                          obj.put("label", parts[k]);
                          arr.put(obj);
                      }
                  }
              }
  
          }
  
      }
  
      System.out.print(arr);
  }
  </code></pre>
  
  <p>Problem is when i run this code I get the following error :</p>
  
  <p>Exception in thread "main" org.json.JSONException: JSONArray[1] not found.</p>
  
  <p>I tried to print arr.length() in each iteration and I get 1!! but I do not really know why i do receive this error?!</p>
  
  <p>Thanks in advance</p>