2 wangxiaoenen wangxiaoenen 于 2015.06.24 16:26 提问

Myeclipse跳转中的强制转换类型出现错误 急急急 !!!求大神指导一下

这是servise包里的可能出错部分
public boolean save(BusRoundExceptionManage pvm) {
BusDeal bd=new BusDeal();
bd.setDealContent(pvm.getReason());
bd.setUnusualBusId(pvm.getId());
this.busdealdao.save(bd);
return true;
}
这是action包里的

public String Update() {
    HttpServletRequest request = ServletActionContext.getRequest();
    Integer pvmid = Integer.parseInt(request.getParameter("pvmid"));
    String reasonable = request.getParameter("manage");
    BusRoundExceptionManage pvm=BusRoundExceptionManageService.queryById(pvmid);
    pvm.setReason(reasonable);
    if(BusRoundExceptionManageService.save(pvm)){
        return "success";
    }
    return "fail";
}

这是Struts里的

    <action name="Update" class="BusRoundExceptionManageAction" method="Update"> 
        <result name="success">/dispatcher/abnormal_handle_next.jsp</result>
        <result name="fail">/dispatcher/abnormal_detail.jsp</result>            
    </action>

这是vo.BusRoundExceptionManage里的
package com.bus.cnu.vo;

import java.util.Date;

public class BusRoundExceptionManage {

private Integer id;
private Date unusualTime;
private String local;
private String unusualType;
private int unusualTypeId;
private String busNo;
private int busId;
private String reason;

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public Date getUnusualTime() {
    return unusualTime;
}

public void setUnusualTime(Date unusualTime) {
    this.unusualTime = unusualTime;
}

public String getLocal() {
    return local;
}

public void setLocal(String local) {
    this.local = local;
}

public String getBusNo() {
    return busNo;
}

public void setBusNo(String busNo) {
    this.busNo = busNo;
}

public String getReason() {
    return reason;
}

public void setReason(String reason) {
    this.reason = reason;
}

public int getBusId() {
    return busId;
}

public void setBusId(int busId) {
    this.busId = busId;
}

public String getUnusualType() {
    return unusualType;
}

public void setUnusualType(String unusualType) {
    this.unusualType = unusualType;
}

public int getUnusualTypeId() {
    return unusualTypeId;
}

public void setUnusualTypeId(int unusualTypeId) {
    this.unusualTypeId = unusualTypeId;
}

}

这是最终报错
HTTP Status 500 - java.lang.ClassCastException: java.lang.String cannot be cast to com.bus.cnu.vo.BusRoundExceptionManage

type Exception report

message java.lang.ClassCastException: java.lang.String cannot be cast to com.bus.cnu.vo.BusRoundExceptionManage

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.ClassCastException: java.lang.String cannot be cast to com.bus.cnu.vo.BusRoundExceptionManage
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:154)
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

3个回答

bulusli3
bulusli3   Ds   Rxr 2015.06.24 16:31


/dispatcher/abnormal_handle_next.jsp
/dispatcher/abnormal_detail.jsp


你这个class要写完整的包,而不是一个类名。比如:class="com.xxx.xxx.BusRoundExceptionManageAction"

wangxiaoenen
wangxiaoenen 我改了还是不对……
2 年多之前 回复
diaoliwei2
diaoliwei2   Rxr 2015.06.24 19:53

java.lang.ClassCastException: java.lang.String cannot be cast to com.bus.cnu.vo.BusRoundExceptionManage 转换出错,那就看看哪里进行了这个转换啊,

diaoliwei2
diaoliwei2 回复wangxiaoenen: 是走到哪报的错啊。queryById这个查询出来的是什么啊
2 年多之前 回复
wangxiaoenen
wangxiaoenen 可是前面string不是是一种类型吗,后面的BusRoundExceptionManage是vo包里的一个类啊,它们怎么可以转换呢 请问那个java.lang.String在哪可以找着啊
2 年多之前 回复
CSDNXiaoF
CSDNXiaoF   2015.06.25 10:49

Action包里的BusRoundExceptionManageService.queryById(pvmid)的返回值是什么类型?
应该不是String,按正常来讲应该是BusRoundExceptionManage 才对,然后检出的项目和BusRoundExceptionManage 里边定义的类型一致起来,
就不会出现转换异常。
如果是String的话,那这肯定不对,查出来的简单类型转换成类,怎么想都不对。

Csdn user default icon
上传中...
上传图片
插入图片