2014-04-20 90 views
0

IM試圖讓primefaces條形圖工作但是我得到以下錯誤的問題:與primefaces條形圖

java.lang.ClassCastException: java.util.Vector cannot be cast to org.primefaces.model.chart.CartesianChartModel 


WARNING: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception 
java.lang.ClassCastException: java.util.Vector cannot be cast to org.primefaces.model.chart.CartesianChartModel 
    at org.primefaces.component.chart.bar.BarChartRenderer.encodeData(BarChartRenderer.java:127) 
    at org.primefaces.component.chart.bar.BarChartRenderer.encodeScript(BarChartRenderer.java:51) 
    at org.primefaces.component.chart.bar.BarChartRenderer.encodeEnd(BarChartRenderer.java:36) 

這裏是代碼:

 <p:barChart id="basic" value="#{markingBean.studentsMarks}" legendPosition="ne" 
        title="Basic Bar Chart" min="0" max="200" style="height:300px"/> 

的studentsMarks檢索從一個後臺bean,做一個數據庫查詢

和db查詢得到我需要的13個標記:

public List getMarksForStudent(Marking id) { 
    System.out.println("In getMarksForStudent"); 
    System.out.println("id = " + id); 
    System.out.println("id = " + id.getId()); 
    Query m = em.createQuery("SELECT m.markSectionOne, m.markSectionTwo, m.markSectionThree, m.markSectionFour, m.markSectionFive, m.markSectionSix, m.markSectionSeven, m.markSectionEight, m.markSectionNine, m.markSectionTen, m.markSectionEleven, m.markSectionTwelve, m.markSectionThirteen FROM MARKING m WHERE m.id = :id", Double.class); 
    m.setParameter("id", id.getId()); // Note the getId() 
    System.out.println(m);  
    return m.getResultList(); 

} 

什麼是導致錯誤,我該如何解決它?

謝謝你們:) :)

回答

1

謝謝你的問題!要求org.primefaces.model.chart.CartesianChartModel值。您指定List類型,因此jvm將顯示java.lang.ClassCastException例外。

請參見下面的鏈接,並按照它: