org.primefaces.component.chart.renderer.BarRenderer.encodeData 处的 NullPointerException

NullPointerException at org.primefaces.component.chart.renderer.BarRenderer.encodeData

我希望我的问题与 类似,但不幸的是答案不适合我。

<p:chart type="bar" model="#{lasDashboardBean.barModel}" style="height:350px">
                            <p:ajax event="itemSelect" listener="#{lasDashboardBean.itemSelect}"  update="machineInfoTable"  />
                        </p:chart>

LasDashboardBean.java

@Named(value = "lasDashboardBean")
@Dependent
public class LasDashboardBean {

private BarChartModel barModel;
private DashboardController dashboardDbController;

@PostConstruct
public void init() {
    try {
        dashboardDbController = new DashboardController();
    } catch (NamingException ex) {
        Logger.getLogger(LasDashboardBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    createBarModel();

}
private void createBarModel() {
    barModel = initBarModel();
    barModel.setTitle("Machine Menufacturers Count");
    barModel.setLegendPosition("ne");

    Axis xAxis = barModel.getAxis(AxisType.X);
    xAxis.setTickAngle(90);

    Axis yAxis = barModel.getAxis(AxisType.Y);
    yAxis.setLabel("Count");
    yAxis.setMin(0);
}
private BarChartModel initBarModel() {
    BarChartModel model = new BarChartModel();
    ChartSeries manufacturersMachines = new ChartSeries();
    manufacturersMachines.setLabel("Machines");
    try {

        manufacturersMachineCount = dashboardDbController.getManufacturersMachinesCount();

        manufacturersMachineCount.stream().forEach((mc) -> {
            manufacturersMachines.set(mc.getManufacturerName(), mc.getCount());
        });

        model.addSeries(manufacturersMachines);

    } catch (SQLException ex) {
        Logger.getLogger(LasDashboardBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    return model;

}

错误日志:

java.lang.NullPointerException at org.primefaces.component.chart.renderer.BarRenderer.encodeData(BarRenderer.java:35) at org.primefaces.component.chart.renderer.BasePlotRenderer.render(BasePlotRenderer.java:29) at org.primefaces.component.chart.ChartRenderer.encodeScript(ChartRenderer.java:95) at org.primefaces.component.chart.ChartRenderer.encodeEnd(ChartRenderer.java:68) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:949) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1912) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeGridBody(PanelGridRenderer.java:244) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeGridLayout(PanelGridRenderer.java:90) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:40) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:949) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1912) at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:918) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1905) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1908) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1908) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:491) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:194) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:151) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:151) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:126) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:223) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:338) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:250) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242) at org.glassfish.grizzly.filterchain.ExecutorResolver.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access0(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573) at java.lang.Thread.run(Thread.java:748)

我在 Glassfish Server 上遇到过同样的问题。 更换服务器后,问题解决。