java.lang.ClassCastException一个类到另一个

时间:2015-04-07 08:04:43

标签: java spring exception

我在点击提交按钮时使用以下代码执行,我收到以下错误并且不确定错误在哪里,有人可以在这里提出建议吗?

private ModelAndView save(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {

        List<FundsProductPurpose> fppList = funderRepository.getFundsList();
        FundsProductPurpose fpp = fppList.get(0);

        return doMapping("result", "Funder details added successfully",
                request);
    } catch (Exception e) {
        e.printStackTrace();
        return doMapping("result", "Unable to add funder details", request);
    }
}

我得到的错误是,

java.lang.ClassCastException: com.mmf.model.FundsDetails cannot be cast to com.mmf.model.FundsProductPurpose
    at com.mmf.controllers.SaveFundsController.save(com.mmf.controllers.SaveFundsController:98)

1 个答案:

答案 0 :(得分:0)

在发布的代码中,您在FundsDetails创建了funderRepository,但您从FudsDetails获得了fundRepository。您应该使用FundsDetails

创建fundRepository
 FundsDetails fundsDetails = new FundsDetails();
 fundsDetails.setIdStaticFunder(funderId);
   .....
 fundRepository.createFund(fundsDetails);// Use fundRepository