为什么我会收到 ClassCastException:
包装异常:
java.lang.ClassCastException: com.avt.model.CasePmt
at com.avt.dao.impl.CasePmtDaoImpl.findAllCasePmt(CasePmtDaoImpl.java:68)
at com.avt.ViewCasePmtAction.view(ViewCasePmtAction.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at gov.pbgc.spectrum.util.SpectrumLookupDispatchAction.execute(SpectrumLookupDispatchAction.java:113)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
我的实现类是
public List<CasePmt> findAllCasePmt() {
List list;
list = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query q = session
.getNamedQuery("findAll");
return q.list();
}
});
Iterator it = list.iterator();
List<CasePmt> l = new ArrayList<CasePmt>();
CasePmt voObj;
while (it.hasNext()) {
voObj = new CasePmt();
Object[] objs = (Object[]) it.next();
// System.out.print("\n" + objs[0].toString());
if (objs[2] != null) {
voObj.setCaseTxNum(objs[1].toString());
}
.......................
}
l.add(voObj);
}
return l;
}
我的行动呼吁是:
List<CasePmt> CsList =
CasePmtBo.getCaseDao().findAllCasePmt();
我在第 68 行遇到错误,即“Object[] objs = (Object[]) it.next();” 线。为什么我会遇到这个问题?
任何输入..我今天重新审视这个并面临这个问题。