Reputation: 3932
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.
Upvotes: 3
Views: 43360
Reputation: 69
This works very fine!. Please try this
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("amt", "1000");
System.out.println("Amount is::"
+ new BigDecimal((String) map.get("amt")));
Upvotes: 0
Reputation: 328594
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
Upvotes: 2
Reputation: 136002
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) {
...
Upvotes: 3
Reputation: 49372
The below line is returning you a java.math.BigDecimal
which you are trying to cast illegaly to Object[]
. It seems yourqueryList
is a List<java.math.BigDecimal>
.
i.next(); // is returning you a java.math.BigDecimal
Upvotes: 0