关于java.lang.Integer cannot be cast to java.lang.Long的 疑问
大家好,我是个J2EE初学者,我写了这么一段代码,但是出现了,类型转换不合法的问题。但是我不清楚为什么会出现这样的错误。希望大家能够帮我看看。谢谢大家了。
public class ScjLogic extends KmapBaseLogic {
// 注入scjdao
private ScjDao scjdao;
public ScjDao getScjdao() {
return scjdao;
}
public void setScjdao(ScjDao scjdao) {
this.scjdao = scjdao;
}
/**
* 初始化技能点页面
* @return
*/
public String initJndScj(){
this.getHttpRequest().getSession().setAttribute("empId",1586);
//String sessionLL = (String)session.getAttribute("sessionLL") ;
Long empId = (Long)this.getHttpRequest().getSession().getAttribute("empId");
List JndName = new ArrayList();
List JndList = scjdao.getJnd(empId);
getHttpRequest().getSession().setAttribute("JndList", JndList);
int listlength = JndList.size();
for(int i=0;i<listlength;i++){
Technology technology = (Technology)JndList.get(i);
List techPathName = scjdao.getJndLjName(technology.getId());
JndName.add(techPathName);
}
getHttpRequest().getSession().setAttribute("JndName",JndName);
return "initjndscjsuccess";
}
错误提示是:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
at com.thunisoft.jndscj.business.service.ScjLogic.initJndScj(ScjLogic.java:36)
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:597)
at com.thunisoft.summer.web.action.MemoryAction.execute(MemoryAction.java:103)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.thunisoft.summer.security.access.filter.ACFilter.doFilter(ACFilter.java:50)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.thunisoft.summer.web.filter.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:619)
2009-05-13 14:12:54,504 [org.apache.struts.util.PropertyMessageResources:352]-[WARN] Resource props/application_zh_CN.properties Not Found.
2009-05-13 14:12:54,504 [org.apache.struts.util.PropertyMessageResources:352]-[WARN] Resource props/application_zh.properties Not Found.
[解决办法]
Long empId = (Long)this.getHttpRequest().getSession().getAttribute("empId");
好像是这个错吧,改成Long empId = Long.parseLong(this.getHttpRequest().getSession().getAttribute("empId").toString()); 试试