Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
NullPointerException when creat a simple chart report
Ethan
<div>Hello, can someone help me about this ?</div>
<div>It's a very simple test code in servlet.</div>
<div>with birt-runtime-4_4_1</div>
<div> </div>
<div>error like this.</div>
<div> </div>
<div>java.lang.NullPointerException</div>
<div>at org.eclipse.birt.chart.factory.Generator.getRowExpressions(Generator.java:1740)</div>
<div>at org.eclipse.birt.chart.factory.Generator.getRowExpressions(Generator.java:587)</div>
<div>at org.eclipse.birt.chart.reportitem.ChartReportItemImpl.getRowExpressions(ChartReportItemImpl.java:978)</div>
<div>at org.eclipse.birt.report.model.util.BoundColumnsMgr.dealExtendedItem(BoundColumnsMgr.java:219)</div>
<div>at org.eclipse.birt.report.model.writer.BoundColumnsWriterMgr.dealExtendedItem(BoundColumnsWriterMgr.java:426)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriterImpl.visitExtendedItem(ModuleWriterImpl.java:1875)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriter.visitExtendedItem(ModuleWriter.java:1)</div>
<div>at org.eclipse.birt.report.model.writer.DesignWriter.visitExtendedItem(DesignWriter.java:1)</div>
<div>at org.eclipse.birt.report.model.elements.ExtendedItem.apply(ExtendedItem.java:136)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeChildren(ModuleWriterImpl.java:2966)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeContents(ModuleWriterImpl.java:2951)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeContents(ModuleWriterImpl.java:2985)</div>
<div>at org.eclipse.birt.report.model.writer.DesignWriterImpl.writeSlot(DesignWriterImpl.java:174)</div>
<div>at org.eclipse.birt.report.model.writer.DesignWriterImpl.visitReportDesign(DesignWriterImpl.java:78)</div>
<div>at org.eclipse.birt.report.model.elements.ReportDesign.apply(ReportDesign.java:65)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeFile(ModuleWriterImpl.java:320)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriterImpl.write(ModuleWriterImpl.java:288)</div>
<div>at org.eclipse.birt.report.model.writer.ModuleWriter.write(ModuleWriter.java:1)</div>
<div>at org.eclipse.birt.report.model.writer.DesignWriter.write(DesignWriter.java:1)</div>
<div>at org.eclipse.birt.report.model.api.ModuleHandleImpl.save(ModuleHandleImpl.java:1456)</div>
<div>at org.eclipse.birt.report.model.api.ModuleHandleImpl.saveAs(ModuleHandleImpl.java:1476)</div>
<div>at com.cs.servlet.SimpleCreate.buildReport(SimpleCreate.java:155)</div>
<div>at com.cs.servlet.SimpleCreate.doGet(SimpleCreate.java:68)</div>
<div>at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)</div>
<div>at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)</div>
<div>at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)</div>
<div>at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)</div>
<div>at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)</div>
<div>at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)</div>
<div>at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)</div>
<div>at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)</div>
<div>at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)</div>
<div>at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)</div>
<div>at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)</div>
<div>at org.mortbay.jetty.Server.handle(Server.java:324)</div>
<div>at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)</div>
<div>at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)</div>
<div>at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)</div>
<div>at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)</div>
<div>at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)</div>
<div>at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)</div>
<div>at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)</div>
<div> </div>
<div> </div>
<div> </div>
<div>here is the code.</div>
<div>error happend when do </div>
<div>design.saveAs(path + "report/sample.rptdesign");</div>
<div> </div>
<div> </div>
<div> </div>
<div>static void buildReport(HttpServletRequest request, HttpServletResponse response) throws IOException, SemanticException {</div>
<div> DesignConfig config = new DesignConfig();</div>
<div> IDesignEngine engine = null;</div>
<div> try {</div>
<div> Platform.startup(config);</div>
<div> IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);</div>
<div> engine = factory.createDesignEngine(config);</div>
<div> } catch (Exception ex) {</div>
<div> ex.printStackTrace();</div>
<div> }</div>
<div> SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);</div>
<div> ReportDesignHandle design = session.createDesign();</div>
<div> ElementFactory efactory = design.getElementFactory();</div>
<div> // create chart</div>
<div> ExtendedItemHandle extendedItemHandle = efactory.newExtendedItem( null, "Chart" ); //$NON-NLS-1$</div>
<div> Chart tempAttachment = createStackedBar(); </div>
<div> extendedItemHandle.getReportItem().setProperty( "chart.instance", tempAttachment);//$NON-NLS-1$</div>
<div> design.getBody().add(extendedItemHandle);</div>
<div> </div>
<div> // save report</div>
<div> String path = request.getSession().getServletContext().getRealPath("/");</div>
<div> System.out.println(path);</div>
<div> design.saveAs(path + "report/sample.rptdesign");</div>
<div> design.close();</div>
<div> // show to viewer</div>
<div> String reportpath = request.getContextPath(); </div>
<div> response.sendRedirect(reportpath + "/frameset?__report=report/sample.rptdesign"); </div>
<div> }</div>
<div> </div>
<div> </div>
<div> </div>
<div>public static final Chart createStackedBar( )</div>
<div> {</div>
<div> ChartWithAxes cwaBar = ChartWithAxesImpl.create( );</div>
<div> cwaBar.setType( "Bar Chart" ); //$NON-NLS-1$</div>
<div> cwaBar.setSubType( "Stacked" ); //$NON-NLS-1$</div>
<div> // Plot</div>
<div> cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );</div>
<div> cwaBar.getBlock( ).getOutline( ).setVisible( true );</div>
<div> Plot p = cwaBar.getPlot( );</div>
<div> p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,255,225 ) );</div>
<div> // Title</div>
<div> cwaBar.getTitle( ).getLabel( ).getCaption( ).setValue( "Stacked Bar Chart" ); //$NON-NLS-1$</div>
<div> // Legend</div>
<div> Legend lg = cwaBar.getLegend( );</div>
<div> lg.setItemType( LegendItemType.SERIES_LITERAL );</div>
<div> // X-Axis</div>
<div> Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];</div>
<div> xAxisPrimary.setType( AxisType.TEXT_LITERAL );</div>
<div> xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );</div>
<div> xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );</div>
<div> // Y-Axis</div>
<div> Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );</div>
<div> yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );</div>
<div> yAxisPrimary.setType( AxisType.LINEAR_LITERAL );</div>
<div> yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );</div>
<div> // Data Set</div>
<div> TextDataSet categoryValues = TextDataSetImpl.create( new String[]{</div>
<div> "Item 1", "Item 2", "Item 3", "Item 4", "Item 5"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$</div>
<div> NumberDataSet orthoValues1 = NumberDataSetImpl.create( new double[]{25, 35, 15, 5, 20} );</div>
<div> NumberDataSet orthoValues2 = NumberDataSetImpl.create( new double[]{5, 10, 25, 10, 5} ); </div>
<div> SampleData sd = DataFactory.eINSTANCE.createSampleData( );</div>
<div> BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );</div>
<div> sdBase.setDataSetRepresentation( "" );//$NON-NLS-1$</div>
<div> sd.getBaseSampleData( ).add( sdBase );</div>
<div> </div>
<div> OrthogonalSampleData sdOrthogonal1 = DataFactory.eINSTANCE.createOrthogonalSampleData( );</div>
<div> sdOrthogonal1.setDataSetRepresentation( "" );//$NON-NLS-1$</div>
<div> sdOrthogonal1.setSeriesDefinitionIndex( 0 );</div>
<div> sd.getOrthogonalSampleData( ).add( sdOrthogonal1 );</div>
<div> </div>
<div> OrthogonalSampleData sdOrthogonal2 = DataFactory.eINSTANCE.createOrthogonalSampleData( );</div>
<div> sdOrthogonal2.setDataSetRepresentation( "" );//$NON-NLS-1$</div>
<div> sdOrthogonal2.setSeriesDefinitionIndex( 1 );</div>
<div> sd.getOrthogonalSampleData( ).add( sdOrthogonal2 );</div>
<div> cwaBar.setSampleData( sd );</div>
<div> // X-Series</div>
<div> Series seCategory = SeriesImpl.create( );</div>
<div> seCategory.setDataSet( categoryValues );</div>
<div> SeriesDefinition sdX = SeriesDefinitionImpl.create( );</div>
<div> xAxisPrimary.getSeriesDefinitions( ).add( sdX );</div>
<div> sdX.getSeries( ).add( seCategory );</div>
<div> // Y-Series</div>
<div> BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );</div>
<div> bs1.setDataSet( orthoValues1 );</div>
<div> bs1.setStacked( true );</div>
<div> bs1.getLabel( ).setVisible( true );</div>
<div> bs1.setLabelPosition( Position.INSIDE_LITERAL );</div>
<div> </div>
<div> BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );</div>
<div> bs2.setDataSet( orthoValues2 );</div>
<div> bs2.setStacked( true );</div>
<div> bs2.getLabel( ).setVisible( true );</div>
<div> bs2.setLabelPosition( Position.INSIDE_LITERAL );</div>
<div> </div>
<div> SeriesDefinition sdY = SeriesDefinitionImpl.create( );</div>
<div> sdY.getSeriesPalette( ).shift( 0 );</div>
<div> yAxisPrimary.getSeriesDefinitions( ).add( sdY );</div>
<div> sdY.getSeries( ).add( bs1 );</div>
<div> sdY.getSeries( ).add( bs2 );</div>
<div> return cwaBar;</div>
<div> }</div>
Find more posts tagged with
Comments
dsoon
<p>Looks like you are missing datasource/dataset the api. </p>
Ethan
<blockquote class="ipsBlockquote" data-author="dsoon" data-cid="131855" data-time="1415181629">
<div>
<p>Looks like you are missing datasource/dataset the api. </p>
</div>
</blockquote>
<p>Hi dsoon, Thank you for your reply. I copy all birt and chart 4.4.1 runtime api to web-inf/lib. What do you means for the "datasource/dataset api"? </p>
dsoon
<p>You had only defined the sample data, I can not see any data source and dataset definition in your code.</p>
Ethan
<blockquote class="ipsBlockquote" data-author="dsoon" data-cid="131876" data-time="1415245033">
<div>
<p>You had only defined the sample data, I can not see any data source and dataset definition in your code.</p>
</div>
</blockquote>
<p>I only use simple array as data like this <span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> new String[]{"</span><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Item 1", "Item 2", "Item 3", "Item 4", "Item 5"}</span>,</p>
<p>So I think I don't need any data source or dataset api ...</p>
wecosphere
<p>I got the same stack trace when using the same code. I suspect its the way the chart is constructed (the exception isn't thrown if the createStackedBar() isn't called) ... didn't manage to dig deeper yet but will try to look at the model of the constructed chart. Did you debug the chart yet to see if there's a specific part of it causing the issue?</p>
Ethan
<blockquote class="ipsBlockquote" data-author="wecosphere" data-cid="131908" data-time="1415294539">
<div>
<p>I got the same stack trace when using the same code. I suspect its the way the chart is constructed (the exception isn't thrown if the createStackedBar() isn't called) ... didn't manage to dig deeper yet but will try to look at the model of the constructed chart. Did you debug the chart yet to see if there's a specific part of it causing the issue?</p>
</div>
</blockquote>
<p>Hi <span style="font-size:12px;font-weight:bold;background-color:rgb(247,247,247);">wecosphere </span>Thank you <span style="font-size:12px;font-weight:bold;background-color:rgb(247,247,247);"> </span></p>
<p>The createStackedBar() function is copy from Eclipse BIRT plug-in [Chart Examples]. I will try other chart later.</p>
wecosphere
<p>HI Ethan,</p>
<p> </p>
<p>Here's an example which works:</p>
<p><a data-ipb='nomediaparse' href='
http://www.eclipsezone.com/servlet/JiveServlet/download/18209-67460-92003636-4346/ChartExample.java'>http://www.eclipsezone.com/servlet/JiveServlet/download/18209-67460-92003636-4346/ChartExample.java</a></p>
;
<p> </p>
<p> </p>
<p>Hope that helps.</p>