I am trying to get started with the simple report designing. I got the sample code from the Birt Home page for Design engine api. But the code itself gives me exceptions. I have spent quite a few hours on this but can't get it working. Can anyone help. Below is the code I am trying to execute with the stacktrace below.
import java.io.IOException;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.GridHandle;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.ImageHandle;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import com.ibm.icu.util.ULocale;
public class ReportDemo
{
public static void main( String[] args )
{
try
{
buildReport( );
}
catch ( IOException e )
{
e.printStackTrace();
}
catch ( SemanticException e )
{
e.printStackTrace();
}
}
static void buildReport( ) throws IOException, SemanticException
{
DesignConfig config = new DesignConfig( );
config.setProperty("BIRT_HOME", "C:/eclipse/birt-runtime-3_7_1/ReportEngine");
IDesignEngine engine = null;
try{
Platform.startup(config);
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );
} catch (BirtException bex) {
bex.printStackTrace();
}catch( Exception ex){
ex.printStackTrace();
}
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
ReportDesignHandle design = session.createDesign( );
ElementFactory factory = design.getElementFactory( );
DesignElementHandle element = factory.newSimpleMasterPage( "Page Master" );
design.getMasterPages( ).add( element );
GridHandle grid = factory.newGridItem( null, 2 /* cols */, 1 /* row */ );
design.getBody( ).add( grid );
grid.setWidth( "100%" );
RowHandle row = (RowHandle) grid.getRows( ).get( 0 );
ImageHandle image = factory.newImage( null );
CellHandle cell = (CellHandle) row.getCells( ).get( 0 );
cell.getContent( ).add( image );
image.setURL( "\"
http://www.eclipse.org/birt/phoenix/tutorial/basic/multichip-4.jpg\"");
LabelHandle label = factory.newLabel( null );
cell = (CellHandle) row.getCells( ).get( 1 );
cell.getContent( ).add( label );
label.setText( "Hello, world!" );
design.saveAs( "c:/sample.rptdesign" );
design.close( );
System.out.println("Finished");
}
}
The stackTrace:
org.eclipse.birt.core.exception.BirtException: Cant startup the OSGI framework
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:91)
at com.entrib.report.ReportDemo.buildReport(ReportDemo.java:63)
at com.entrib.report.ReportDemo.main(ReportDemo.java:36)
Caused by: org.eclipse.birt.core.exception.CoreException
at org.eclipse.birt.core.framework.osgi.OSGILauncher.startup(OSGILauncher.java:90)
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:79)
... 2 more
Exception in thread "main" java.lang.NullPointerException
at com.entrib.report.ReportDemo.buildReport(ReportDemo.java:74)
at com.entrib.report.ReportDemo.main(ReportDemo.java:36)
Can anyone help?
Thank You,
Juhi.