Home » Archived » BIRT » java.lang.NullPointerException, at org.eclipse.birt.chart.factory.Generator.getRowExpressions
java.lang.NullPointerException, at org.eclipse.birt.chart.factory.Generator.getRowExpressions [message #283764] |
Thu, 24 January 2008 15:19 |
Eclipse User |
|
|
|
Originally posted by: Salvatore.Contu.gmail.com
Hi all,
I'm trying to create a chart programmatically, and like test I've copied
a method in org.eclipse.birt.chart.examples_2.1.1.v20070705-1847. My
Datasets are this:
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
"March", "April", "May", "June", "July"} );
NumberDataSet orthoValues1 = NumberDataSetImpl.create( new double[]{
12.5, 19.6, 18.3, 13.2, 26.5
} );
When Birt executes my class it always throws this exception:
java.lang.NullPointerException, at
org.eclipse.birt.chart.factory.Generator.getRowExpressions
Any idea ?
Thanks,
Salvatore
p.s: I am depressed for all these problems to create a very stupid and
trivial chart.
|
|
|
Re: java.lang.NullPointerException, at org.eclipse.birt.chart.factory.Generator.getRowExpressions [message #518197 is a reply to message #283764] |
Wed, 03 March 2010 13:22 |
Carl Emmoth Messages: 8 Registered: March 2010 |
Junior Member |
|
|
I have exactly the same problem within the following code. It throws exception @design.saveAs( designFilename ) :
private void makeNewTab(String birtHome, String birtEngine, String birtLog,
String name, String driver, String url, String user, char[] password,
String select, String from,
String designFilename, String reportFilename, String htmlFilename,
boolean cake) {
JScrollPane scrollis = new JScrollPane();
System.out.println("Starting ...");
try {
// Startup
EngineConfig config = new EngineConfig();
config.setEngineHome(birtEngine);
config.setLogConfig(birtLog, Level.WARNING);
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_ REPORT_ENGINE_FACTORY);
IReportEngine engine = factory.createReportEngine(config);
System.out.println("Engine is set up ...");
// Create new design
DesignConfig config2 = new DesignConfig();
config2.setProperty("BIRT_HOME", birtHome);
IDesignEngine engine2 = null;
try {
Platform.startup(config2);
IDesignEngineFactory factory2 = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_ DESIGN_ENGINE_FACTORY);
engine2 = factory2.createDesignEngine(config2);
} catch (Exception e) {
e.printStackTrace();
}
SessionHandle session = engine2.newSessionHandle(ULocale.ENGLISH);
ReportDesignHandle design = session.createDesign();
ElementFactory factory3 = design.getElementFactory();
// Required
DesignElementHandle element = factory3.newSimpleMasterPage("Page Master");
design.getMasterPages().add(element);
// Create cake?
ExtendedItemHandle chartItem = factory3.newExtendedItem("Cake", "Chart"); // "Chart" with capital C!!
//chartItem.setProperty(ExtendedItemHandle.DATA_SET_PROP, "ChartData");
chartItem.setProperty("outputFormat", "PNG");
chartItem.getReportItem().setProperty("chart.instance", createPie());
design.getBody().add(chartItem);
// Save the design and close it.
design.saveAs( designFilename ); //$NON-NLS-1$
design.close( );
System.out.println("Finished");
// DynamicTable finished ...
IReportRunnable design2 = engine.openReportDesign(designFilename);
IRunTask task = engine.createRunTask(design2);
task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOA DER_KEY, this.getClass().getClassLoader());
task.run(reportFilename);
task.close();
// Html
IReportDocument document = engine.openReportDocument(reportFilename);
IRenderTask render = engine.createRenderTask(document);
render.getAppContext().put(EngineConstants.APPCONTEXT_CLASSL OADER_KEY, this.getClass().getClassLoader());
//String filename = "C:/dev/BIRT/ReportWindow/output/test_" + System.currentTimeMillis() + ".html";
IRenderOption options = new RenderOption();
options.setOutputFormat("html");
options.setOutputFileName(htmlFilename);
HTMLRenderOption htmlOptions = new HTMLRenderOption(options);
htmlOptions.setImageDirectory("C:/dev/BIRT/ReportWindow/output ");
htmlOptions.setHtmlPagination(false);
htmlOptions.setHtmlRtLFlag(false);
htmlOptions.setEmbeddable(false);
IRenderTask rendertask = engine.createRenderTask(document);
rendertask.setRenderOption(options);
//rendertask.setRenderOption(htmlOptions);
rendertask.render();
document.close();
// Show html-page
File file = new File(htmlFilename);
JEditorPane editor = new JEditorPane();
System.out.println("Opening file:" + file.toURI().toURL().toString());
editor.setPage(file.toURI().toURL());
scrollis.getViewport().add(editor);
tabbedpane.addTab(htmlFilename, iconReport, scrollis, "Check out the new file!!");
// Close
engine.destroy();
Platform.shutdown();
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
}
System.out.println("Done!");
}
// Code from Eclipse examples
public Chart createPie( )
{
ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( );
cwoaPie.setDimension( ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL );
cwoaPie.setType( "Pie Chart" ); //$NON-NLS-1$
cwoaPie.setSubType( "Standard Pie Chart" ); //$NON-NLS-1$
// Plot
cwoaPie.setSeriesThickness( 10 );
// Legend
Legend lg = cwoaPie.getLegend( );
lg.getOutline( ).setVisible( true );
// Title
cwoaPie.getTitle( ).getLabel( ).getCaption( ).setValue( "Pie Chart" );//$NON-NLS-1$
// Data Set
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
"New York", "Boston", "Chicago", "San Francisco", "Dallas"} );//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{
54.65, 21, 75.95, 91.28, 37.43
} );
SampleData sdata = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "" );
sdata.getBaseSampleData( ).add( sdBase );
OrthogonalSampleData sdOrthogonal = DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal.setDataSetRepresentation( "" );//$NON-NLS-1$
sdOrthogonal.setSeriesDefinitionIndex( 0 );
sdata.getOrthogonalSampleData( ).add( sdOrthogonal );
cwoaPie.setSampleData( sdata );
// Base Series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );
SeriesDefinition sd = SeriesDefinitionImpl.create( );
cwoaPie.getSeriesDefinitions( ).add( sd );
sd.getSeriesPalette( ).shift( 0 );
sd.getSeries( ).add( seCategory );
// Orthogonal Series
PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
sePie.setDataSet( seriesOneValues );
sePie.setSeriesIdentifier( "Cities" );//$NON-NLS-1$
sePie.setExplosion( 5 );
SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
sd.getSeriesDefinitions( ).add( sdCity );
sdCity.getSeries( ).add( sePie );
return cwoaPie;
}
[Updated on: Wed, 03 March 2010 13:24] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Apr 19 12:37:07 GMT 2024
Powered by FUDForum. Page generated in 0.01699 seconds
|