I'm appending to a list then throwing that list into a function below:
List<ItemBean> itemList;
for (Object bean : beans)
{
if (!bean.getItem().isActive())
{
itemList.add(bean.getItem().getId());
}
}
if (!itemList.isEmpty())
{
// Source of Supply List
buildItemList( request, commonDAO, false );
}
else{
buildItemFilterList( request, commonDAO, itemList);
}
But I'm getting "Can only iterate over an array or an instance of java.lang.Iterable" error here:
protected final List<ItemBean> buildItemFilterList( HttpServletRequest request,
CommonDAO dao,
ItemBean list
)
throws Exception
{
List<ItemBean> itemList = dao.getAllItems( false );
ItemBean item;
for (ItemBean s: list ) <<<<<-----ERROR!!!!!!!!!!!
{
item = dao.getItemById(s.getId());
itemList.add(item);
}
Collections.sort( itemList );
request.setAttribute("itemList", itemList);
return itemList;
}
The error is, that your argument "SourceOfSupplyBean list" is not a collection.
protected final List<ItemBean> buildItemFilterList(
HttpServletRequest request,
CommonDAO dao,
List<ItemBean> list
)
Apparently, parameter 'list' is of type of ItemBean
and ItemBean
is not an instance of Iterable
or an array.
protected final List<ItemBean> buildItemFilterList( HttpServletRequest request,
CommonDAO dao,
ItemBean list
)
throws Exception
{
List<ItemBean> itemList = dao.getAllItems( false );
ItemBean item;
for (ItemBean s: list ) <<<<<-----ERROR!!!!!!!!!!!
{
item = dao.getItemById(s.getId());
itemList.add(item); <<< --real error is here.
}
Collections.sort( itemList );
request.setAttribute("itemList", itemList);
return itemList;
}
You cannot modify a list while iterating through it.
throws Exception
is not very sensible - Niklas B. 2012-04-04 20:07