Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.math.BigDecimal cannot be cast to [Ljava.lang.Object;

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.

like image 401
Dev Avatar asked Jan 28 '26 19:01

Dev


2 Answers

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) {
   ...
like image 165
Evgeniy Dorofeev Avatar answered Jan 30 '26 09:01

Evgeniy Dorofeev


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

like image 33
Aaron Digulla Avatar answered Jan 30 '26 11:01

Aaron Digulla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!