我将附加到列表中,然后将该列表放入以下函数中:
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);
}
但是我得到了“只能迭代数组或java.lang.Iterable的实例”错误:
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;
}
答案 0 :(得分:5)
错误是,您的参数“SourceOfSupplyBean list”不是集合。
protected final List<ItemBean> buildItemFilterList(
HttpServletRequest request,
CommonDAO dao,
List<ItemBean> list
)
答案 1 :(得分:0)
显然,参数'list'的类型为ItemBean
,而ItemBean
不是Iterable
的实例或数组。
答案 2 :(得分:0)
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;
}
迭代时无法修改列表。