What is wrong with below code ?
List<Object[]> currencies = null;
List<String> currencyList = new ArrayList<String>();
//code to fetch currency
String currencySql = "select C.Currency from Currency C";
Query currencyQuery = this.em.createQuery(currencySql);
currencies = currencyQuery.getResultList();
for (Object[] currency : currencies) { //getting runtime error here
for (int i = 0; i < currency.length; i++) {
currencyList.add(currency[i].toString());
}
}
Getting runtime error in first line of for loop as: java.lang.ClassCastException: java.lang.String incompatible with [Ljava.lang.Object;
The code compiles alright.
What is the issue ?