I have a ListView that has an EditText in each row. The user can update the value that is populated in the EditText, and then click a button to refresh the new sum at the top of the ListView. My approach here is to loop through all ListView records and obtain the value of the EditText, perform the necessary calculations, then update the UI. My problem is I keep receiving a NullPointerException on my fifth iteration, even though there is definitely a value populated. It works fine for the first four iterations. Is my code correct and/or should I be taking a different approach for what I'm trying to do:
button_finish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double sumOfAppliedAmounts = 0;
Bundle extras = getIntent().getExtras();
double exchange_rate = Double.parseDouble(extras.getString("exchange_rate")) / 100;
double convertedPaymentAmount;
if (exchange_rate >= 1)
convertedPaymentAmount = Double.parseDouble(extras.getString("payment_amount")) / exchange_rate;
else
convertedPaymentAmount = Double.parseDouble(extras.getString("payment_amount")) * exchange_rate;
for (int i = 0; i < (m_listview.getCount()); i++) {
v = m_listview.getChildAt(i);
applied_amount = (EditText) v.findViewById(R.id.list_text_applied_amount_value);
sumOfAppliedAmounts = sumOfAppliedAmounts + Double.parseDouble(applied_amount.getText().toString());
}
text_remaining_converted_amount.setText(String.valueOf(convertedPaymentAmount - sumOfAppliedAmounts));
}
});