我试图让素数面条形图工作,但我得到了以下错误:
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中检索的
studentsMarks = markingFacade.getMarksForStudent(markToEdit);
数据库查询得到我需要的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();
}
错误的原因是什么?我该如何修复?
谢谢大家:)
谢谢你的提问!
<p:barChart
需要org.primefaces.model.chart.CartesianChartModel
值。您分配了List
类型,所以jvm将显示java.lang.ClassCastException
异常。
请参阅下面的链接,并关注它:
- 图表-条形图