title: Java Android Json OutOfMemoryError
body: <p>I'm trying to decode a json string and do something with the contents. I have this code that runs whenever the user presses a button:</p>
  
  <pre><code>public List&lt;Card&gt; readCards()
  {
      List&lt;Card&gt; cards = new ArrayList&lt;Card&gt;();
  
      HttpReader httpReader = new HttpReader();
      httpReader.setOnResultReadyListener(new HttpReader.OnResultReadyListener() {
          @Override
          public void resultReady(String result) {
              JsonHelper jsonHelper = new JsonHelper();
              List&lt;Card&gt; cards = jsonHelper.getCards(result);
  
              for (int i = 0; i &lt; cards.size(); i++ ) {
                  cards.add(new Card(cards.get(i).getId(), cards.get(i).getNaam(), cards.get(i).getMana(), cards.get(i).getAttack(), cards.get(i).getHealth(), cards.get(i).getEffect(), cards.get(i).getZeldzaamheid(), cards.get(i).getTypeId(), cards.get(i).getSubtypeId(), cards.get(i).getClassId(), cards.get(i).isGoud()));
              }
          }
      });
      httpReader.execute("http://jsonstring.com"); //link to json-file
  
      return cards;
  }
  </code></pre>
  
  <p>The <code>getCards(result)</code> method from the <code>jsonHelper</code> class is this:</p>
  
  <pre><code>public List&lt;Card&gt; getCards(String jsonText) {
      List&lt;Card&gt; list= new ArrayList&lt;Card&gt;();
  
      try {
          JSONArray jsonArrayCards = new JSONArray(jsonText);
          for (int i = 0; i &lt; jsonArrayCards.length(); i++) {
              JSONObject jsonObjectCard = jsonArrayCards.getJSONObject(i);    
  
                  Card card = new Card();
                  if ( jsonObjectCard.has("id")) { card.setId(jsonObjectCard.getString("id")); } else { card.setId("none"); }
                  if ( jsonObjectCard.has("name")) { card.setNaam(jsonObjectCard.getString("name")); } else { card.setNaam("none"); }
                  if ( jsonObjectCard.has("cost")) { card.setMana(jsonObjectCard.getInt("cost")); } else { card.setMana(0); }
                  if ( jsonObjectCard.has("attack")) { card.setAttack(jsonObjectCard.getInt("attack")); } else { card.setAttack(0); }
                  if ( jsonObjectCard.has("health")) { card.setHealth(jsonObjectCard.getInt("health")); } else { card.setHealth(0); }
                  if ( jsonObjectCard.has("text")) { card.setEffect(jsonObjectCard.getString("text")); } else { card.setEffect(""); }
                  card.setTypeId(1);
                  card.setSubtypeId(1);
                  card.setClassId(1);
                  list.add(card);
          }
      } catch (JSONException e) {
          Log.e("JSON Parser", "Error parsing data " + e.toString());
      }
  
      return list;
  }
  </code></pre>
  
  <p>After this is done I'm trying to show to the size of the returned list, which is 0 for some reason.</p>
  
  <p>After clicking the button the first time the app freezes. Log shows a <code>java.lang.OutOfMemoryError</code></p>
  
  <p>The json file is &lt;200 lines which is maybe 5kb so that should not be a problem.</p>
  
  <p>Any help would be much appreciated.</p>