您好我有ArrayList
泛型类型是Bean类类型。当我尝试从ArrayList
获取数据时,我会收到异常。
以下是代码:
ArrayList<IRUserSegment> segments = (ArrayList<IRUserSegment>) userSegmentDAO.getDateWiseCount(org.getOrgId());
System.out.println("List size"+segments.size());
// IRUserSegment itr=segments.get(1);//getting Iterator from arraylist to traverse elements
for (int i = 0; i < segments.size(); i++) {
IRUserSegment value = segments.get(i);
System.out.println("Element: " + value.getCount());
}
DAO CODE public List getDateWiseCount(Integer orgId){
IRUserSegment usersegment = null;
try
{
q.append("SELECT count(*) as cnt, date(updatedOn) as updatedOnDate FROM t_user_segment WHERE updatedOn >= DATE_SUB(CURRENT_DATE, INTERVAL 15 DAY) group by updatedOnDate;");
SQLQuery query = session.createSQLQuery(q.toString());
segmentList = (List<IRUserSegment>) query.list();
//ArrayList<IRUserSegment> details=(ArrayList<IRUserSegment>)
if (segmentList != null && segmentList.size() > 0)
{
List<Object[]> result = query.list();
for (Object[] object : result)
{
System.out.println("Count"+object[0].toString()+"date"+object[1].toString());
}
return segmentList;
}
}
catch (Exception e)
{
log.error("", e);
}
return segmentList;
}
答案 0 :(得分:0)
尝试使用这样的。
List segments = userSegmentDAO.getDateWiseCount(org.getOrgId());
System.out.println("List size"+segments.size());
// IRUserSegment itr=segments.get(1);//getting Iterator from arraylist to traverse elements
for (int i = 0; i < segments.size(); i++) {
IRUserSegment value = (IRUserSegment)segments.get(i);
System.out.println("Element: " + value.getCount());
}
或您将方法修改为
public List<IRUserSegment> getDateWiseCount(Integer orgId) {}
而不是
public List getDateWiseCount(Integer orgId) {}