List queryList = executeReadAllSQLQuery(queryString);
for (Iterator i = queryList.iterator(); i.hasNext();) {
Object values[] = (Object[]) i.next();
FDetails pDetails = transform(values);
fDList.add(pDetails);
values = null;
}
Error I am getting at line 3 : java.math.BigDecimal cannot be cast to [Ljava.lang.Object;
My transform function :
private FDetails transform(Object[] values) {
FDetails Details = new FDetails();
Details.setPb((BigDecimal)values[0]);
Details.setPm((BigDecimal)values[1]);
Details.setEl((BigDecimal)values[1]);
Details.setUl((BigDecimal)values[1]);
return BalanceDetails;
}
Please help me resolve these issue.
It's clear from error that your List queryList is in fact a list of BigDecimals. So this would be work
BigDecimal value = (BigDecimal) i.next();
but since it's not what you expect then executeReadAllSQLQuery returns wrong result
BTW for-each would look better anyway
for (Object obj : queryList) {
...
How about this code:
@SuppressWarnings("rawtypes")
List<BigDecimal> queryList = executeReadAllSQLQuery(queryString);
FDetails details = new FDetails();
int i = 0;
details.setPb(queryList.get(i ++));
details.setPm(queryList.get(i ++));
...
fDList.add(pDetails);
Note: Calling fDList.add() inside of the loop is almost certainly wrong. The loop gets one value from the list but you want all five values from the list, create one instance of FDetails from those five values and add that single instance to fDList once
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With