struts2-java.lang.ClassCastException

问题描述

java.lang.ClassCastException
struts2 action

private List<GanttTask> ganttTaskList = null; ganttTaskList = ganttTaskDao.gtList(task_id);                                  for(int i = 0;i<ganttTaskList.size();i++){                                              cname = ganttTaskList.get(i).getOther_field();                                      }

这句话有什么错?为什么总是报错

java.lang.ClassCastException: org.apache.commons.collections.map.ListOrderedMap cannot be cast to com.smic.mfg.bean.GanttTask    at com.smic.mfg.action.TaskListAction.query(TaskListAction.java:102)    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.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:270)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)    at java.lang.Thread.run(Thread.java:662)

解决方案

 rg.apache.commons.collections.map.ListOrderedMap cannot be cast to com.smic.mfg.bean.GanttTask List<GanttTask> ganttTaskList = ganttTaskDao.gtList(task_id);  //看看这个方法返回的list和你定义的是否一致。

解决方案二:

org.apache.commons.collections.map.ListOrderedMap cannot be cast to com.smic.mfg.bean.GanttTaskListListOrderedMap不能转换为GanttTask  ganttTaskDao.gtList() 这个方法的返回类型应该是定义成了ListListOrderedMap看错误应该是  ganttTaskDao.gtList() 这个方法定义的返回类型是错了,可能是import的时候搞错了。

解决方案三:
# 类转换异常啊,这个错你都能犯?

解决方案四:
dao

List<GanttTask> gtList(String task_id) throws Exception;

impl

    @Override    public List<GanttTask> gtList(String task_id) throws Exception {        String sql = ""select b.task_idnamepercent_doneto_char(a.start_date'yyyy-mm-dd')start_dateto_char(a.end_date'yyyy-mm-dd')end_date +other_fielddurationpid""index"" from task aJMP_TB_PROJECT b where a.pid=to_number(SUBSTR(b.TASK_ID66)) and b.task_id=? "";        return jt.queryForList(sqlnew Object[]{task_id});    }

bean

 package com.smic.mfg.bean;import java.io.UnsupportedEncodingException;import java.util.Date;public class GanttTask {    private Integer id;    private Date start_date;    private Date end_date;    private Integer percent_done;    private String name;    private Integer priority;    private String baseline_start_date;    private String baseline_end_date;    private Integer parent_id;    private Double duration;    private String duration_unit;    private String other_field;    private Integer pid;    private Integer index;    private String task_id;    public String getTask_id() {        return task_id;    }    public void setTask_id(String task_id) {        this.task_id = task_id;    }    public Date getStart_date() {        return start_date;    }    public void setStart_date(Date start_date) {        this.start_date = start_date;    }    public Date getEnd_date() {        return end_date;    }    public void setEnd_date(Date end_date) {        this.end_date = end_date;    }    public String getBaseline_start_date() {        return baseline_start_date;    }    public void setBaseline_start_date(String baseline_start_date) {        this.baseline_start_date = baseline_start_date;    }    public String getBaseline_end_date() {        return baseline_end_date;    }    public void setBaseline_end_date(String baseline_end_date) {        this.baseline_end_date = baseline_end_date;    }    public Integer getId() {        return id;    }    public void setId(Integer id) {        this.id = id;    }    public Integer getPercent_done() {        return percent_done;    }    public void setPercent_done(Integer percent_done) {        this.percent_done = percent_done;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public Integer getPriority() {        return priority;    }    public void setPriority(Integer priority) {        this.priority = priority;    }    public Integer getParent_id() {        return parent_id;    }    public void setParent_id(Integer parent_id) {        this.parent_id = parent_id;    }    public Double getDuration() {        return duration;    }    public void setDuration(Double duration) {        this.duration = duration;    }    public String getDuration_unit() {        return duration_unit;    }    public void setDuration_unit(String duration_unit) {        this.duration_unit = duration_unit;    }    public String getOther_field() throws UnsupportedEncodingException {        return other_field;    }    public void setOther_field(String other_field) {        this.other_field = other_field;    }    public Integer getPid() {        return pid;    }    public void setPid(Integer pid) {        this.pid = pid;    }    public Integer getIndex() {        return index;    }    public void setIndex(Integer index) {        this.index = index;    }}

问题何在?

时间: 2024-12-05 18:06:33

struts2-java.lang.ClassCastException的相关文章

java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcesso

org.apache.jasper.JasperException: java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor         at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletW

java.lang.ClassCastException

问题描述 调用下面方法后,publicvoidsave(CapestransientInstance){log.debug("savingCapesinstance");try{getHibernateTemplate().save(transientInstance);log.debug("savesuccessful");}catch(RuntimeExceptionre){log.error("savefailed",re);throwre

db4o数据库存放的class含有相同的字段名且字段的类型也相同。现在想把这个库中数据读出来,但总是报 java.lang.ClassCastException错误

db4o数据库存放的class含有相同的字段名且字段的类型也相同.现在想把这个库中数据读出来,但总是报 java.lang.ClassCastException错误,请大侠指教 具体情况如下:   ObjectContainer db =null;    try {    db = Db4o.openFile("bean.yap");List<AlarmFilter> list_a = db.get(AlarmFilter.class);     for(int x = 0

iterator-最后一句的输出应该怎么写才会有键值对输出? java.lang.ClassCastException

问题描述 最后一句的输出应该怎么写才会有键值对输出? java.lang.ClassCastException public class Student { private String name; private String sex; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return se

java.lang.ClassCastException: com.sun.proxy.$Proxy27 cannot be cast to com.bbk.n002.service.QuestionService

1 严重: Servlet /N002-1.0 threw load() exception 2 java.lang.ClassCastException: com.sun.proxy.$Proxy27 cannot be cast to com.bbk.n002.service.QuestionService 3 at com.bbk.n002.servlet.CreateTaskQueueServlet.init(CreateTaskQueueServlet.java:28) 4 at ja

[Domino]“java.lang.ClassCastException:lotus.domino.cso.Item”异常解决办法

[Domino] "java.lang.ClassCastException:lotus.domino.cso.Item" 异常解决办法 编写者 日期 关键词 郑昀@ultrapower 2005-6 Java Domino RichTextItem   现象 通过Domino的Document.getFirstItem("Body")是可以获取当前邮件的Body字段,并试图直接转换为RichTextItem类型,从而访问该邮件的附件. 但是,有时候这个转换得到了下

jboss容器分离后启动时报出java.lang.ClassCastException

问题描述 jboss容器分离后启动时报出java.lang.ClassCastException 在做一个jboss容器分离的,已经新建了profile目录,而且deploy下我也确定只有一个ear发布包和一个数据源的xml配置.但是在启动的时候还是报出以下的问题 11:40:17,822 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=dcBackEnd-bet

java.lang.ClassCastException: Dispatch object expected

问题描述 运行项目出现异常:java.lang.ClassCastException:Dispatchobjectexpectedatcom.jacob.com.Dispatch.invokev(Dispatch.java:803)atcom.jacob.com.Dispatch.get(Dispatch.java:1153)atcom.lyang.governmentbill.utility.report.Java2Word.getTables(Java2Word.java:665)atcom

weblogic部署web项目报错java.lang.ClassCastException

问题描述 tomcat本地测试都是可以的,但在weblogic上部署,就会报错:java.lang.RuntimeException:UnabletocreateXMLReaderatorg.jasig.cas.client.util.XmlUtils.getXmlReader(XmlUtils.java:58)atorg.jasig.cas.client.util.XmlUtils.getTextForElement(XmlUtils.java:130)atorg.jasig.cas.clie

求高手解答 java.lang.ClassCastException: org.quartz.simpl.SimpleThreadPool

问题描述 使用quartz的时候,启动程序就抛出如下异常,不知道问题出在那,求解决...严重:Spring容器初始化过程中出现异常[wrzs_core]org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'getScheduling':Invocationofinitmethodfailed;nestedexceptionisorg.quartz.SchedulerException:T