Home Analytics Developing analytics applications
The community of Analytics developers are invited to follow and participate in the developer network.
OpenText technical experts collaborate with supported customers and partners in the Magellan product area.

BIRT runtime simple example giving exception

<p style="font-size:15px;color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;">I am attempting to create a report using BIRT runtime (4.5) and below is the code I used for creating a simple demo.</p>
<pre class="_prettyXprint">
public static void main(String[] args) {
try {
} catch (IOException e) {
// TODO Auto-generated catch block
} catch (SemanticException e) {
// TODO Auto-generated catch block

// This function shows how to build a very simple BIRT report with a
// minimal set of content: a simple grid with an image and a label.

static void buildReport() throws IOException, SemanticException {

String birtRuntimePath = "C:\\birt-runtime-4_5_0\\ReportEngine\\";
// Create a session handle. This is used to manage all open designs.
// Your app need create the session only once.

// Configure the Engine and start the Platform
DesignConfig config = new DesignConfig();

// config.setProperty("BIRT_HOME", birtRuntimePath);
IDesignEngine engine = null;
try {

IDesignEngineFactory factoryDesignEngine = (IDesignEngineFactory) Platform
engine = factoryDesignEngine.createDesignEngine(config);

SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);

// Create a new report design.

ReportDesignHandle design = session.createDesign();

// The element factory creates instances of the various BIRT elements.

ElementFactory factory = design.getElementFactory();

// Create a simple master page that describes how the report will
// appear when printed.
// Note: The report will fail to load in the BIRT designer
// unless you create a master page.

DesignElementHandle element = factory.newSimpleMasterPage("Page Master"); //$NON-NLS-1$

// Create a grid and add it to the "body" slot of the report
// design.

GridHandle grid = factory.newGridItem(null, 2 /* cols */, 1 /* row */ );

// Note: Set the table width to 100% to prevent the label
// from appearing too narrow in the layout view.

grid.setWidth("100%"); //$NON-NLS-1$

// Get the first row.

RowHandle row = (RowHandle) grid.getRows().get(0);

// Create an image and add it to the first cell.

ImageHandle image = factory.newImage(null);
CellHandle cell = (CellHandle) row.getCells().get(0);

// Create a label and add it to the second cell.

LabelHandle label = factory.newLabel(null);
cell = (CellHandle) row.getCells().get(1);
label.setText("Hello, world!"); //$NON-NLS-1$

// Save the design and close it.

design.saveAs("C:/Test/sample.rptdesign"); //$NON-NLS-1$

// We're done!

} catch (Exception ex) {
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">POM.xml</span></p>
<pre class="_prettyXprint">



<p style="font-size:15px;color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;">When I run the main method in eclipse or maven, I usually have a NullPointerException on this line</p>
<pre class="_prettyXprint">
engine = factoryDesignEngine.createDesignEngine(config);
<p style="font-size:15px;color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;">Run the program again in eclipse using debug mode and found that factoryDesignEngine variable is null.</p>
<pre class="_prettyXprint">
IDesignEngineFactory factoryDesignEngine = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);</pre>
<p style="font-size:15px;color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;">I understand that this line is supposed to initialize factoryDesignEngine but I don't understand why it says it's null. Maybe there is a setup problem or a configuration problem on my eclipse. I have already all the dependencies resolved in Maven but I still can't get it to work. The original code is found <a data-ipb='nomediaparse' href='http://www.eclipse.org/birt/resources/documentation/integrating/DeDemo.java'>here</a> and made a bit of modification, I've seen articles claiming that they were able to run the sample program just fine.</p>
<p style="font-size:15px;color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;">Any help is greatly appreciated.</p>
Sign In or Register to comment.