What I'm trying to do is get the sum of all integer items retrieved from the database then added into a LinkedList, like so:
ManageFeeNotePOJO selectedRecord = (ManageFeeNotePOJO) manageFeeNoteListTableView().getItems().get(selectdIndex);
List toFeeBillListTot = new LinkedList();
toFeeBillListTot.add(selectedRecord.getFeeNoteValue());
int sum = 0;
for (Object sumItem : toFeeBillListTot) {
sum += sumItem;
}
System.out.println(sum);
With this I get the error:
bad operand types for binary operator '+'
first type: int
second type: Object
The other approach is:
ManageFeeNotePOJO selectedRecord = (ManageFeeNotePOJO) manageFeeNoteListTableView().getItems().get(selectdIndex);
List toFeeBillListTot = new LinkedList();
toFeeBillListTot.add(selectedRecord.getFeeNoteValue());
int sum = 0;
for (int i = 0; i < toFeeBillListTot.size(); i++) {
sum += (int) toFeeBillListTot.get(i);
}
System.out.println(sum);
I get java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
error with this
Please, I would be more than greatful for any working approach around this. Thank you in advance.