2015-04-07 58 views
0

我使用下面的代碼來執行時,點擊提交按鈕,我收到以下錯誤,並不知道錯誤在哪裏,任何人都可以在這裏給我一個建議嗎?我越來越java.lang.ClassCastException一個類到其他

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) 
+0

你試着投了'FundsDetails'成'FundsProductPurpose'。我們並不真正瞭解這些類,所以很難說,但是您可能希望將「FundsDetails」設置爲「FundsProductPurpose」的子類。 – Dragondraikk

+0

98是什麼? – dunni

+0

第98行是... FundsProductPurpose fpp = fppList.get(0); – DevGo

回答

0

從公佈的代碼,你funderRepository創建FundsDetails,但你從fundRepositoryFudsDetails。您應該創建FundsDetailsfundRepository

FundsDetails fundsDetails = new FundsDetails(); 
fundsDetails.setIdStaticFunder(funderId); 
    ..... 
fundRepository.createFund(fundsDetails);// Use fundRepository 
+0

當你獲取時改變了我的代碼...但仍存在同樣的問題...我用新代碼更新了我的問題 – DevGo

+0

I我能夠從funderRepository.getFundsList()獲得列表,但是錯誤只發生在第98行。(FundsProductPurpose fpp = fppList.get(0);) – DevGo