title: Android - for loop terminating early
body: <p>I'm trying to manipulate a JSONArray, <code>rawJArr</code>, (taken from the Reddit API), and get the url and a bitmap (taken from the gfycat "API") from each object to create an ArrayList (<code>listing</code>) of <code>Highlight</code> instances which will be converted to a <code>CardView</code> containing a picture, a short description, and a link to the gfycat.</p>
  
  <pre><code>try {
  
      int count = 0;
      int highlightMax;
      Bitmap bitmap = null;
      Highlight curHighlight;
      myJSON = new JSONObject(rawJSON);
      curJSON = myJSON.getJSONObject("data");
      rawJArr = curJSON.getJSONArray("children");
  
      String strHighlightNo =  mySPrefs.getString("pref_highlightNo", "notFound");
  
      if(strHighlightNo.equals("notFound")) {
          Log.w("FT", "shared pref not found");
          return null;
      }
  
      highlightMax = Integer.parseInt(strHighlightNo);
  
      Log.w("Arr Length", Integer.toString(rawJArr.length()));
      Log.w("Highlight No", Integer.toString(highlightMax));
  
      for(int i=0; i &lt; rawJArr.length(); i++) {
  
          Log.w("Count", Integer.toString(count));
          Log.w("I", Integer.toString(i));
  
          if(count == highlightMax) {
              Log.w("FT", "Breakpoint reached!");
              break;
          }
  
          curJSON = rawJArr.getJSONObject(i).getJSONObject("data");
  
          String url = curJSON.getString("url");
          String[] parts = url.split("//");
          String imageUrl = "http://thumbs." + parts[1] + "-thumb100.jpg";
  
          try {
              bitmap = BitmapFactory.decodeStream((InputStream) new URL(imageUrl).getContent());
          } catch (MalformedURLException e) {
              e.printStackTrace();
          }
  
          // if there is no available picture, then don't include one in the Highlight
          if(bitmap == null) {
              Log.w("FT", "Null bitmap");
              curHighlight = new Highlight(curJSON.getString("title"), url, null);
              listing.add(curHighlight);
              count++;
          } else {
              Log.w("FT", "Bitmap Available");
              curHighlight = new Highlight(curJSON.getString("title"), url, bitmap);
              listing.add(curHighlight);
              count++;
          }
  
      }
  
  
      } catch(JSONException e) {
          e.printStackTrace();
          return listing;
      }
  </code></pre>
  
  <p>However, my for loop terminates way too early. The current JSONArray I'm using has a length of 25, and I've specified a <code>pref_highlightNo</code> of 15, but my for loop terminates after 6 iterations.</p>
  
  <p>My <code>Log.w</code> tests in the for loop all record the same count (Count: 1, Integer: 1 - Count: 6, Integer: 6).</p>
  
  <p>I'm struggling to see why my loop is terminating: there is no stack trace printed to my console, and my app doesn't crash.</p>
  
  <p>Any idea what's going on?</p>