title: sum for loop quantity values?
body: <p>i have this code..</p>
  
  <pre><code>JSONObject jsonObjcart = new JSONObject(myJSONCartProducts);
  jsonarrayCartProducts = jsonObjcart.getJSONArray("cartproducts");
  
  cartarraylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  for (int i = 0; i &lt; jsonarrayCartProducts.length(); i++) {
      HashMap&lt;String, String&gt; lmap = new HashMap&lt;String, String&gt;();
      JSONObject p = jsonarrayCartProducts.getJSONObject(i);
      // Retrive JSON Objects
      lmap.put("products_id", p.getString("products_id"));
      lmap.put("products_name", p.getString("products_name"));
      lmap.put("products_price", p.getString("products_price"));
      lmap.put("products_image", p.getString("products_image"));
      lmap.put("customers_basket_quantity", p.getString("customers_basket_quantity"));
      lmap.put("products_price_total", p.getString("products_price_total"));
      lmap.put("pcustomersid", customersid);
      lmap.put("pcountryid", countryid);
      lmap.put("customers_basket_id", p.getString("customers_basket_id"));
      // Set the JSON Objects into the array
      cartarraylist.add(lmap);
  }
  </code></pre>
  
  <p>i want to sum the quantity <code>p.getString("customers_basket_quantity")</code> and set to my textview..</p>
  
  <p>i tried to do create an </p>
  
  <pre><code>int qtySum=0;
  int qtyNum;
  </code></pre>
  
  <p>and do this inside for loop..</p>
  
  <pre><code>qtyNum = Integer.parseInt(p.getString("customers_basket_quantity"));
          qtySum += qtyNum;
  </code></pre>
  
  <p>and set qtySum to my textview</p>
  
  <pre><code>textTotalitems.setText(qtySum);
  </code></pre>
  
  <p>but i got error, the app crashed..</p>
  
  <p>this is updated code with sum i tried..</p>
  
  <pre><code>JSONObject jsonObjcart = new JSONObject(myJSONCartProducts);
  jsonarrayCartProducts = jsonObjcart.getJSONArray("cartproducts");
  
  cartarraylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  int qtySum=0;
  int qtyNum;
  for (int i = 0; i &lt; jsonarrayCartProducts.length(); i++) {
      HashMap&lt;String, String&gt; lmap = new HashMap&lt;String, String&gt;();
      JSONObject p = jsonarrayCartProducts.getJSONObject(i);
      // Retrive JSON Objects
      lmap.put("products_id", p.getString("products_id"));
      lmap.put("products_name", p.getString("products_name"));
      lmap.put("products_price", p.getString("products_price"));
      lmap.put("products_image", p.getString("products_image"));
      lmap.put("customers_basket_quantity", p.getString("customers_basket_quantity"));
      lmap.put("products_price_total", p.getString("products_price_total"));
      lmap.put("pcustomersid", customersid);
      lmap.put("pcountryid", countryid);
      lmap.put("customers_basket_id", p.getString("customers_basket_id"));
      // Set the JSON Objects into the array
      qtyNum = Integer.parseInt(p.getString("customers_basket_quantity"));
      qtySum += qtyNum;
      cartarraylist.add(lmap);
  }
  textTotalitems.setText(qtySum);
  </code></pre>