title: Calculating the sum of Firebase records values
body: <p>I have a database structure like this one here.</p>
  
  <p><a href="https://i.stack.imgur.com/WlVvo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WlVvo.png" alt="enter image description here"></a></p>
  
  <p>My objective is to get the total of the two amounts 12000 and 15000 and that would be 27000..However the code i have tried to use is giving me a value like <strong>null1200015000</strong> . Here is the code:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_mystatement);
          listview = (ListView) findViewById(R.id.listview);
  
          textView4 = (TextView) findViewById(R.id.textView4);
  
  
          dref = FirebaseDatabase.getInstance().getReference();
  
  
          DatabaseReference dref = FirebaseDatabase.getInstance().getReference();
          dref = dref.child("Expenditure");
  
          dref.addValueEventListener(new ValueEventListener() {
  
  
              @Override
              public void onDataChange(DataSnapshot snapshot) {
                  for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                      //Getting the data from snapshot
                      DogExpenditure dogExpenditure = postSnapshot.getValue(DogExpenditure.class);
  
                      //Adding it to a stringString expenses = "Amount: "+dogExpenditure.getAmount()+"\nReason for Use: "+dogExpenditure.getItem()+"\n\n";
  
                      String amount =  dogExpenditure.getAmount();
  
  
                      textView4.setText(amount);
                  }
  
  
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
  
  
              public void onCancelled(FirebaseError firebaseError) {
                  System.out.println("The read failed: " + firebaseError.getMessage());
              }
          });
  </code></pre>
  
  <p>Anyone with an idea on how to achieve this???
  Here is my DogExpenditure class:</p>
  
  <pre><code>public class DogExpenditure {
      private String amount;
      private String item;
  
      public String getAmount() {
          return amount;
      }
  
      public void setAmount(String amount) {
          this.amount = amount;
      }
  
      public String getItem() {
          return item;
      }
  
      public void setItem(String item) {
          this.item = item;
      }
  }
  </code></pre>