问题描述
严重:Servlet.service()forservletPieChartthrewexceptionjava.lang.NullPointerExceptionatcom.etcxm.shouwangzhe.jfreechart.PieChartServlet.createPieDataset(PieChartServlet.java:77)atcom.etcxm.shouwangzhe.jfreechart.PieChartServlet.doPost(PieChartServlet.java:48)atcom.etcxm.shouwangzhe.jfreechart.PieChartServlet.doGet(PieChartServlet.java:40)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:690)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:416)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)atjava.lang.Thread.run(Thread.java:619)=================================================================================出现空指针异常具体的代码如下:publicclassPieChartServletextendsHttpServlet{privatestaticfinallongserialVersionUID=-3798298158506030366L;privateICpccmxServicecpccmxService;privateCpccmxVOcpccmxVO;publicPieChartServlet(){super();}publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{this.doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//设置返回类型为图片response.setContentType("image/png");//获取数据集对象PieDatasetdataset=createPieDataset(request);//创建图形对象JFreeChartjfreechart=ChartFactory.createPieChart3D("片烟成品产出",dataset,true,true,false);//获得图表区域对象PiePlotpieplot=(PiePlot)jfreechart.getPlot();//设置图表区域的标签字体pieplot.setLabelFont(newFont("宋体",0,12));//设置图表区域无数据时的默认显示文字pieplot.setNoDataMessage("没有产出数据");//设置图表区域不是圆形,由于是3D的饼形图,建议设置为falsepieplot.setCircular(false);//设置图表区域文字与图表区域的间隔距离,0.02表示2%pieplot.setLabelGap(0.02D);//将图表已数据流的方式返回给客户端ChartUtilities.writeChartAsPNG(response.getOutputStream(),jfreechart,512,512);}/***返回数据集**@return*/privatePieDatasetcreatePieDataset(HttpServletRequestrequest){//创建饼形图数据集对象DefaultPieDatasetdefaultpiedataset=newDefaultPieDataset();Sessionsession=HibernateSessionFactory.getSession();List<Object>list=session.createSQLQuery("selectdjdm,sum(pyjs)fromcpccmxgroupbydjdm").list();if(list!=null){for(inti=0;i<list.size();i++){Object[]array=(Object[])list.get(i);//分别图形区域的说明和数据defaultpiedataset.setValue((Comparable)array[0],(Number)array[1]);}}*returndefaultpiedataset;/*//测试例子defaultpiedataset.setValue("苹果",100);defaultpiedataset.setValue("香蕉",200);defaultpiedataset.setValue("梨子",300);returndefaultpiedataset;*/}//getsetpublicICpccmxServicegetCpccmxService(){returncpccmxService;}publicvoidsetCpccmxService(ICpccmxServicecpccmxService){this.cpccmxService=cpccmxService;}publicCpccmxVOgetCpccmxVO(){returncpccmxVO;}publicvoidsetCpccmxVO(CpccmxVOcpccmxVO){this.cpccmxVO=cpccmxVO;}在线等,哪位大大帮忙解决下,困扰了好多天万分感谢!!!
解决方案
解决方案二:
createPieDataset77行是哪一行啊
解决方案三:
/***返回数据集**@return*/privatePieDatasetcreatePieDataset(HttpServletRequestrequest){//创建饼形图数据集对象DefaultPieDatasetdefaultpiedataset=newDefaultPieDataset();Sessionsession=HibernateSessionFactory.getSession();List<Object>list=session.createSQLQuery("selectdjdm,sum(pyjs)fromcpccmxgroupbydjdm").list();if(list!=null){for(inti=0;i<list.size();i++){Object[]array=(Object[])list.get(i);//分别图形区域的说明和数据defaultpiedataset.setValue((Comparable)array[0],(Number)array[1]);}}*returndefaultpiedataset;/*//测试例子defaultpiedataset.setValue("苹果",100);defaultpiedataset.setValue("香蕉",200);defaultpiedataset.setValue("梨子",300);returndefaultpiedataset;*/}