'DataSnapshot method onDataChange crashing

I am reading my crash report and I found an issue in my DataSnapShot, but I am not sure if it has something to do with my implementation, I see no issues in logcat, but it does crash in real phones.

see my implementation, what I want is to display the total amount spent on the current day so I iterate the ds and add new amounts to it.

private void todayTotalAmountSpent() {
    final Calendar c = Calendar.getInstance();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String date = dateFormat.format(c.getTime());

    DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Expenses").child(mAuth.getCurrentUser().getUid());
    Query query = reference.orderByChild("date").equalTo(date);
    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {
            int totalAmount = 0;

            for (DataSnapshot ds : snapshot.getChildren()) {
                Expense expense = ds.getValue(Expense.class);
                totalAmount += expense.getAmount();

                String currencyTotal = formatNumberCurrency(String.valueOf(totalAmount));

                totalAmountToday.setText("$ " + currencyTotal);
            }

        }

        @Override
        public void onCancelled(@NonNull DatabaseError error) {

        }
    });

}

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source