爲什麼我得到ClassCastException異常: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();」線。 爲什麼我會遇到這個問題?
任何inputs..im今天重新審視這個問題,並面臨問題。
我將它轉換爲CasePmt,但仍然在獲得相同的異常在同一行#。 – JNPW
@JNPW:你可以分享你的findAll查詢嗎? –
其 「SELECT * FROM JTL.Case_VW」 – JNPW