Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » NULL Pointer Exception problem
NULL Pointer Exception problem [message #251104] Fri, 03 August 2007 14:17 Go to next message
Eclipse UserFriend
Originally posted by: antonin.slezacek.cloudsmith.com

Hi,

I don't know why this throws me NULLPointeException

OdaDataSourceHandle dataSourceHandle =
elementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");

I found this peace of code on the web and many more uses the same syntax
with some little differences like jdbc etc..

Could you help me to fix it.

exactly:
private void createDataSources()
{
try {
OdaDataSourceHandle dataSourceHandle;
dataSourceHandle =
elementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");

dataSourceHandle.setProperty("FILELIST",
"/home/slezi/workspace/rep/data/result-1180445164703.xml");


designHandle.getDataSources().add(dataSourceHandle);
}
catch (SemanticException e) { e.printStackTrace();
}
}

this is the exception it throws
java.lang.NullPointerException
at subreport.createDataSources(subreport.java:40)
at subreport.start(subreport.java:99)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Re: NULL Pointer Exception problem [message #251152 is a reply to message #251104] Fri, 03 August 2007 18:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Can you post the entire routine or specify which line below is throwing
the exception?

Jason

slezi wrote:
> Hi,
>
> I don't know why this throws me NULLPointeException
>
> OdaDataSourceHandle dataSourceHandle =
> elementFactory.newOdaDataSource("Data Source",
> "org.eclipse.birt.report.data.oda.xml");
>
> I found this peace of code on the web and many more uses the same syntax
> with some little differences like jdbc etc..
>
> Could you help me to fix it.
>
> exactly:
> private void createDataSources()
> {
> try {
> OdaDataSourceHandle dataSourceHandle;
> dataSourceHandle =
> elementFactory.newOdaDataSource("Data Source",
> "org.eclipse.birt.report.data.oda.xml");
>
> dataSourceHandle.setProperty("FILELIST",
> "/home/slezi/workspace/rep/data/result-1180445164703.xml");
>
>
> designHandle.getDataSources().add(dataSourceHandle);
> }
> catch (SemanticException e) { e.printStackTrace();
> }
> }
>
> this is the exception it throws
> java.lang.NullPointerException
> at subreport.createDataSources(subreport.java:40)
> at subreport.start(subreport.java:99)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Re: NULL Pointer Exception problem [message #251156 is a reply to message #251152] Fri, 03 August 2007 19:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Here is a working example of this:

Jason

XML File
<people>
<person>
<name>Jonathan</name>
<nicknames>
<nickname>John</nickname>
<nickname>Jon</nickname>
</nicknames>
</person>
<person>
<name>Steven</name>
<nicknames>
<nickname>Steve</nickname>
</nicknames>
</person>
</people>

Code

import java.io.File;
import java.io.IOException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException ;
import org.eclipse.birt.report.model.api.command.ContentException;
import org.eclipse.birt.report.model.api.command.NameException;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
import org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
import org.eclipse.birt.report.model.api.metadata.IMetaDataDictiona ry;
import org.eclipse.birt.report.model.elements.interfaces.IReportIte mModel;
import org.eclipse.birt.report.model.elements.interfaces.IStyleMode l;

import com.ibm.icu.util.ULocale;

public class XMLReport
{

ReportDesignHandle reportDesignHandle = null;

ElementFactory elementFactory = null;

IMetaDataDictionary dict = null;

ComputedColumn cs1, cs2, cs3 = null;

public static void main( String[] args ) throws SemanticException,
IOException
{
new XMLReport( ).createReport( );
}

void createReport( ) throws SemanticException, IOException
{
//Configure the Engine and start the Platform
DesignConfig config = new DesignConfig( );

config.setProperty("BIRT_HOME",
"C:/birt/birt-runtime-2_2_0/birt-runtime-2_2_0/ReportEngine");
IDesignEngine engine = null;
try{


Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );

}catch( Exception ex){
ex.printStackTrace();
}


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


// Create a new report
reportDesignHandle = session.createDesign( );

// Element factory is used to create instances of BIRT elements.
elementFactory = reportDesignHandle.getElementFactory( );

dict = new DesignEngine( null ).getMetaData( );

createMasterPages( );
createDataSources( );
createDataSets( );
createBody( );

String outputPath = "output";//$NON-NLS-1$
File outputFolder = new File( outputPath );
if ( !outputFolder.exists( ) && !outputFolder.mkdir( ) )
{
throw new IOException( "Can not create the output folder"
);//$NON-NLS-1$
}
reportDesignHandle.saveAs( "output/desample/XMLReport.rptdesign"
);//$NON-NLS-1$//$NON-NLS-2$
System.out.println("finished");
}

//Scripted Data Set
/*
* private void createDataSources( ) throws SemanticException
{
ScriptDataSourceHandle dataSourceHandle =
elementFactory.newScriptDataSource( "Data Source" );//$NON-NLS-1$
reportDesignHandle.getDataSources( ).add( dataSourceHandle );
}

private void createDataSets( ) throws SemanticException
{
// Data Set
ScriptDataSetHandle dataSetHandle = elementFactory.newScriptDataSet(
"Data
Set" );//$NON-NLS-1$
dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$

// Set open( ) in code
dataSetHandle.setOpen( "i=0;"//$NON-NLS-1$
+ "sourcedata = new Array( new Array(3), new Array(3), new Array(3),
new Array(3));"//$NON-NLS-1$

+ "sourcedata[0][0] = 10; "//$NON-NLS-1$
+ "sourcedata[0][1] = \"Ice Bella\";"//$NON-NLS-1$
+ "sourcedata[0][2] = 304;"//$NON-NLS-1$

+ "sourcedata[1][0] = 10; "//$NON-NLS-1$
+ "sourcedata[1][1] = \"Nola Dicci\";"//$NON-NLS-1$
+ "sourcedata[1][2] = 258;"//$NON-NLS-1$

+ "sourcedata[2][0] = 11; "//$NON-NLS-1$
+ "sourcedata[2][1] = \"Ice Bella\";"//$NON-NLS-1$
+ "sourcedata[2][2] = 202;"//$NON-NLS-1$

+ "sourcedata[3][0] = 11; "//$NON-NLS-1$
+ "sourcedata[3][1] = \"Nola Dicci\";"//$NON-NLS-1$
+ "sourcedata[3][2] = 181;" );//$NON-NLS-1$

// Set fetch( ) in code
dataSetHandle.setFetch( "if ( i < 4 ){"//$NON-NLS-1$
+ "row[\"Month\"] = sourcedata[i][0];"//$NON-NLS-1$
+ "row[\"Product\"] = sourcedata[i][1];"//$NON-NLS-1$
+ "row[\"Amount\"] = sourcedata[i][2];"//$NON-NLS-1$
+ "i++;"//$NON-NLS-1$
+ "return true;}" + "else return false;" );//$NON-NLS-1$//$NON-NLS-2$

// Set computed columns
cs1 = StructureFactory.createComputedColumn( );
cs1.setName( "Month" );//$NON-NLS-1$
cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
cs1.setDataType( "integer" );//$NON-NLS-1$

cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "Product" );//$NON-NLS-1$
cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
cs2.setDataType( "string" );//$NON-NLS-1$

cs3 = StructureFactory.createComputedColumn( );
cs3.setName( "Amount" );//$NON-NLS-1$
cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
cs3.setDataType( "integer" );//$NON-NLS-1$

PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
computedSet.addItem( cs1 );
computedSet.addItem( cs2 );
computedSet.addItem( cs3 );

reportDesignHandle.getDataSets( ).add( dataSetHandle );
}
*/



private void createDataSources( ) throws SemanticException
{
OdaDataSourceHandle dataSourceHandle =
elementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");
dataSourceHandle.setProperty("FILELIST", "C:/temp/xmltest.xml");
reportDesignHandle.getDataSources( ).add( dataSourceHandle );
}

private void createDataSets( ) throws SemanticException
{
// Data Set

OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( "Data Set",
"org.eclipse.birt.report.data.oda.xml.dataSet" );
dsHandle.setDataSource( "Data Source" );
dsHandle.setQueryText(
" table0#-TNAME-#table0#:#[/people/person/name]#:#{name;String ;} " );

reportDesignHandle.getDataSets( ).add( dsHandle );


}

private void createMasterPages( ) throws ContentException, NameException
{
DesignElementHandle simpleMasterPage =
elementFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
reportDesignHandle.getMasterPages( ).add( simpleMasterPage );
}



private void createBody( ) throws SemanticException
{



TableHandle table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
table.setProperty( IStyleModel.TEXT_ALIGN_PROP,
DesignChoiceConstants.TEXT_ALIGN_CENTER );
table.setWidth( "80%" );//$NON-NLS-1$
table.setProperty( IReportItemModel.DATA_SET_PROP, "Data Set"
);//$NON-NLS-1$

PropertyHandle computedSet = table.getColumnBindings( );
cs1 = StructureFactory.createComputedColumn( );

cs1.setName("Name");
cs1.setExpression( "dataSetRow[\"name\"]" );//$NON-NLS-1$
computedSet.addItem( cs1 );



// Header
RowHandle header = (RowHandle) table.getHeader( ).get( 0 );

CellHandle tcell = (CellHandle) header.getCells( ).get( 0 );
LabelHandle label = elementFactory.newLabel( null );
label.setText( "Name" );//$NON-NLS-1$
tcell.getContent( ).add( label );



DataItemHandle data = null;
// Detail
RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
tcell = (CellHandle) detail.getCells( ).get( 0 );
data = elementFactory.newDataItem( null );
data.setResultSetColumn( cs1.getName( ) );
tcell.getContent( ).add( data );


reportDesignHandle.getBody( ).add( table );


}


}


Jason Weathersby wrote:
> Can you post the entire routine or specify which line below is throwing
> the exception?
>
> Jason
>
> slezi wrote:
>> Hi,
>>
>> I don't know why this throws me NULLPointeException
>>
>> OdaDataSourceHandle dataSourceHandle =
>> elementFactory.newOdaDataSource("Data Source",
>> "org.eclipse.birt.report.data.oda.xml");
>>
>> I found this peace of code on the web and many more uses the same syntax
>> with some little differences like jdbc etc..
>>
>> Could you help me to fix it.
>>
>> exactly:
>> private void createDataSources()
>> {
>> try {
>> OdaDataSourceHandle dataSourceHandle;
>> dataSourceHandle =
>> elementFactory.newOdaDataSource("Data Source",
>> "org.eclipse.birt.report.data.oda.xml");
>>
>> dataSourceHandle.setProperty("FILELIST",
>> "/home/slezi/workspace/rep/data/result-1180445164703.xml");
>>
>>
>> designHandle.getDataSources().add(dataSourceHandle);
>> }
>> catch (SemanticException e) {
>> e.printStackTrace();
>> }
>> }
>>
>> this is the exception it throws
>> java.lang.NullPointerException
>> at subreport.createDataSources(subreport.java:40)
>> at subreport.start(subreport.java:99)
>> at
>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
>>
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
>>
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
>>
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
>>
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at
>> org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
>> at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
>> at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Re: NULL Pointer Exception problem [message #251166 is a reply to message #251156] Fri, 03 August 2007 19:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: antonin.slezacek.cloudsmith.com

This line throws it

OdaDataSourceHandle dataSourceHandle =
elementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");


Jason Weathersby napsal(a):
> Here is a working example of this:
>
> Jason
>
> XML File
> <people>
> <person>
> <name>Jonathan</name>
> <nicknames>
> <nickname>John</nickname>
> <nickname>Jon</nickname>
> </nicknames>
> </person>
> <person>
> <name>Steven</name>
> <nicknames>
> <nickname>Steve</nickname>
> </nicknames>
> </person>
> </people>
>
> Code
>
> import java.io.File;
> import java.io.IOException;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.report.model.api.CellHandle;
> import org.eclipse.birt.report.model.api.DataItemHandle;
> import org.eclipse.birt.report.model.api.DesignConfig;
> import org.eclipse.birt.report.model.api.DesignElementHandle;
> import org.eclipse.birt.report.model.api.DesignEngine;
> import org.eclipse.birt.report.model.api.ElementFactory;
> import org.eclipse.birt.report.model.api.IDesignEngine;
> import org.eclipse.birt.report.model.api.IDesignEngineFactory;
> import org.eclipse.birt.report.model.api.LabelHandle;
> import org.eclipse.birt.report.model.api.PropertyHandle;
> import org.eclipse.birt.report.model.api.ReportDesignHandle;
> import org.eclipse.birt.report.model.api.RowHandle;
> import org.eclipse.birt.report.model.api.OdaDataSetHandle;
> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
> import org.eclipse.birt.report.model.api.SessionHandle;
> import org.eclipse.birt.report.model.api.StructureFactory;
> import org.eclipse.birt.report.model.api.TableHandle;
> import org.eclipse.birt.report.model.api.activity.SemanticException ;
> import org.eclipse.birt.report.model.api.command.ContentException;
> import org.eclipse.birt.report.model.api.command.NameException;
> import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
> import
> org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
> import org.eclipse.birt.report.model.api.metadata.IMetaDataDictiona ry;
> import org.eclipse.birt.report.model.elements.interfaces.IReportIte mModel;
> import org.eclipse.birt.report.model.elements.interfaces.IStyleMode l;
>
> import com.ibm.icu.util.ULocale;
>
> public class XMLReport
> {
>
> ReportDesignHandle reportDesignHandle = null;
>
> ElementFactory elementFactory = null;
>
> IMetaDataDictionary dict = null;
>
> ComputedColumn cs1, cs2, cs3 = null;
>
> public static void main( String[] args ) throws SemanticException,
> IOException
> {
> new XMLReport( ).createReport( );
> }
>
> void createReport( ) throws SemanticException, IOException
> {
> //Configure the Engine and start the Platform
> DesignConfig config = new DesignConfig( );
>
> config.setProperty("BIRT_HOME",
> "C:/birt/birt-runtime-2_2_0/birt-runtime-2_2_0/ReportEngine");
> IDesignEngine engine = null;
> try{
>
>
> Platform.startup( config );
> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
> .createFactoryObject(
> IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
> engine = factory.createDesignEngine( config );
>
> }catch( Exception ex){
> ex.printStackTrace();
> }
>
>
> SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
>
>
> // Create a new report
> reportDesignHandle = session.createDesign( );
>
> // Element factory is used to create instances of BIRT elements.
> elementFactory = reportDesignHandle.getElementFactory( );
>
> dict = new DesignEngine( null ).getMetaData( );
>
> createMasterPages( );
> createDataSources( );
> createDataSets( );
> createBody( );
>
> String outputPath = "output";//$NON-NLS-1$
> File outputFolder = new File( outputPath );
> if ( !outputFolder.exists( ) && !outputFolder.mkdir( ) )
> {
> throw new IOException( "Can not create the output folder"
> );//$NON-NLS-1$
> }
> reportDesignHandle.saveAs( "output/desample/XMLReport.rptdesign"
> );//$NON-NLS-1$//$NON-NLS-2$
> System.out.println("finished");
> }
>
> //Scripted Data Set
> /*
> * private void createDataSources( ) throws SemanticException
> {
> ScriptDataSourceHandle dataSourceHandle =
> elementFactory.newScriptDataSource( "Data Source" );//$NON-NLS-1$
> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
> }
>
> private void createDataSets( ) throws SemanticException
> {
> // Data Set
> ScriptDataSetHandle dataSetHandle = elementFactory.newScriptDataSet(
> "Data
> Set" );//$NON-NLS-1$
> dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$
>
> // Set open( ) in code
> dataSetHandle.setOpen( "i=0;"//$NON-NLS-1$
> + "sourcedata = new Array( new Array(3), new Array(3), new Array(3),
> new Array(3));"//$NON-NLS-1$
>
> + "sourcedata[0][0] = 10; "//$NON-NLS-1$
> + "sourcedata[0][1] = \"Ice Bella\";"//$NON-NLS-1$
> + "sourcedata[0][2] = 304;"//$NON-NLS-1$
>
> + "sourcedata[1][0] = 10; "//$NON-NLS-1$
> + "sourcedata[1][1] = \"Nola Dicci\";"//$NON-NLS-1$
> + "sourcedata[1][2] = 258;"//$NON-NLS-1$
>
> + "sourcedata[2][0] = 11; "//$NON-NLS-1$
> + "sourcedata[2][1] = \"Ice Bella\";"//$NON-NLS-1$
> + "sourcedata[2][2] = 202;"//$NON-NLS-1$
>
> + "sourcedata[3][0] = 11; "//$NON-NLS-1$
> + "sourcedata[3][1] = \"Nola Dicci\";"//$NON-NLS-1$
> + "sourcedata[3][2] = 181;" );//$NON-NLS-1$
>
> // Set fetch( ) in code
> dataSetHandle.setFetch( "if ( i < 4 ){"//$NON-NLS-1$
> + "row[\"Month\"] = sourcedata[i][0];"//$NON-NLS-1$
> + "row[\"Product\"] = sourcedata[i][1];"//$NON-NLS-1$
> + "row[\"Amount\"] = sourcedata[i][2];"//$NON-NLS-1$
> + "i++;"//$NON-NLS-1$
> + "return true;}" + "else return false;" );//$NON-NLS-1$//$NON-NLS-2$
>
> // Set computed columns
> cs1 = StructureFactory.createComputedColumn( );
> cs1.setName( "Month" );//$NON-NLS-1$
> cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
> cs1.setDataType( "integer" );//$NON-NLS-1$
>
> cs2 = StructureFactory.createComputedColumn( );
> cs2.setName( "Product" );//$NON-NLS-1$
> cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
> cs2.setDataType( "string" );//$NON-NLS-1$
>
> cs3 = StructureFactory.createComputedColumn( );
> cs3.setName( "Amount" );//$NON-NLS-1$
> cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
> cs3.setDataType( "integer" );//$NON-NLS-1$
>
> PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
> ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
> computedSet.addItem( cs1 );
> computedSet.addItem( cs2 );
> computedSet.addItem( cs3 );
>
> reportDesignHandle.getDataSets( ).add( dataSetHandle );
> }
> */
>
>
>
> private void createDataSources( ) throws SemanticException
> {
> OdaDataSourceHandle dataSourceHandle =
> elementFactory.newOdaDataSource("Data Source",
> "org.eclipse.birt.report.data.oda.xml");
> dataSourceHandle.setProperty("FILELIST", "C:/temp/xmltest.xml");
> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
> }
>
> private void createDataSets( ) throws SemanticException
> {
> // Data Set
>
> OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( "Data Set",
> "org.eclipse.birt.report.data.oda.xml.dataSet" );
> dsHandle.setDataSource( "Data Source" );
> dsHandle.setQueryText(
> " table0#-TNAME-#table0#:#[/people/person/name]#:#{name;String ;} " );
>
> reportDesignHandle.getDataSets( ).add( dsHandle );
>
>
> }
>
> private void createMasterPages( ) throws ContentException, NameException
> {
> DesignElementHandle simpleMasterPage =
> elementFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
> reportDesignHandle.getMasterPages( ).add( simpleMasterPage );
> }
>
>
>
> private void createBody( ) throws SemanticException
> {
>
>
>
> TableHandle table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
> table.setProperty( IStyleModel.TEXT_ALIGN_PROP,
> DesignChoiceConstants.TEXT_ALIGN_CENTER );
> table.setWidth( "80%" );//$NON-NLS-1$
> table.setProperty( IReportItemModel.DATA_SET_PROP, "Data Set"
> );//$NON-NLS-1$
>
> PropertyHandle computedSet = table.getColumnBindings( );
> cs1 = StructureFactory.createComputedColumn( );
>
> cs1.setName("Name");
> cs1.setExpression( "dataSetRow[\"name\"]" );//$NON-NLS-1$
> computedSet.addItem( cs1 );
>
>
>
> // Header
> RowHandle header = (RowHandle) table.getHeader( ).get( 0 );
>
> CellHandle tcell = (CellHandle) header.getCells( ).get( 0 );
> LabelHandle label = elementFactory.newLabel( null );
> label.setText( "Name" );//$NON-NLS-1$
> tcell.getContent( ).add( label );
>
>
>
> DataItemHandle data = null;
> // Detail
> RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
> tcell = (CellHandle) detail.getCells( ).get( 0 );
> data = elementFactory.newDataItem( null );
> data.setResultSetColumn( cs1.getName( ) );
> tcell.getContent( ).add( data );
>
>
> reportDesignHandle.getBody( ).add( table );
>
>
> }
>
>
> }
>
>
> Jason Weathersby wrote:
>> Can you post the entire routine or specify which line below is
>> throwing the exception?
>>
>> Jason
>>
>> slezi wrote:
>>> Hi,
>>>
>>> I don't know why this throws me NULLPointeException
>>>
>>> OdaDataSourceHandle dataSourceHandle =
>>> elementFactory.newOdaDataSource("Data Source",
>>> "org.eclipse.birt.report.data.oda.xml");
>>>
>>> I found this peace of code on the web and many more uses the same syntax
>>> with some little differences like jdbc etc..
>>>
>>> Could you help me to fix it.
>>>
>>> exactly:
>>> private void createDataSources()
>>> {
>>> try {
>>> OdaDataSourceHandle dataSourceHandle;
>>> dataSourceHandle =
>>> elementFactory.newOdaDataSource("Data Source",
>>> "org.eclipse.birt.report.data.oda.xml");
>>> dataSourceHandle.setProperty("FILELIST",
>>> "/home/slezi/workspace/rep/data/result-1180445164703.xml");
>>>
>>> designHandle.getDataSources().add(dataSourceHandle);
>>> }
>>> catch (SemanticException e) {
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> this is the exception it throws
>>> java.lang.NullPointerException
>>> at subreport.createDataSources(subreport.java:40)
>>> at subreport.start(subreport.java:99)
>>> at
>>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
>>>
>>> at
>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
>>>
>>> at
>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
>>>
>>> at
>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
>>>
>>> at
>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
>>>
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>
>>> at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>> at
>>> org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
>>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
>>> at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
>>> at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Re: NULL Pointer Exception problem [message #251199 is a reply to message #251166] Sat, 04 August 2007 02:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Can you try the example I attached.

Also in your example is elementFactory null?
Is this the only Data Source in the report?


Thanks

Jason

slezi wrote:
> This line throws it
>
> OdaDataSourceHandle dataSourceHandle =
> elementFactory.newOdaDataSource("Data Source",
> "org.eclipse.birt.report.data.oda.xml");
>
>
> Jason Weathersby napsal(a):
>> Here is a working example of this:
>>
>> Jason
>>
>> XML File
>> <people>
>> <person>
>> <name>Jonathan</name>
>> <nicknames>
>> <nickname>John</nickname>
>> <nickname>Jon</nickname>
>> </nicknames>
>> </person>
>> <person>
>> <name>Steven</name>
>> <nicknames>
>> <nickname>Steve</nickname>
>> </nicknames>
>> </person>
>> </people>
>>
>> Code
>>
>> import java.io.File;
>> import java.io.IOException;
>> import org.eclipse.birt.core.framework.Platform;
>> import org.eclipse.birt.report.model.api.CellHandle;
>> import org.eclipse.birt.report.model.api.DataItemHandle;
>> import org.eclipse.birt.report.model.api.DesignConfig;
>> import org.eclipse.birt.report.model.api.DesignElementHandle;
>> import org.eclipse.birt.report.model.api.DesignEngine;
>> import org.eclipse.birt.report.model.api.ElementFactory;
>> import org.eclipse.birt.report.model.api.IDesignEngine;
>> import org.eclipse.birt.report.model.api.IDesignEngineFactory;
>> import org.eclipse.birt.report.model.api.LabelHandle;
>> import org.eclipse.birt.report.model.api.PropertyHandle;
>> import org.eclipse.birt.report.model.api.ReportDesignHandle;
>> import org.eclipse.birt.report.model.api.RowHandle;
>> import org.eclipse.birt.report.model.api.OdaDataSetHandle;
>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>> import org.eclipse.birt.report.model.api.SessionHandle;
>> import org.eclipse.birt.report.model.api.StructureFactory;
>> import org.eclipse.birt.report.model.api.TableHandle;
>> import org.eclipse.birt.report.model.api.activity.SemanticException ;
>> import org.eclipse.birt.report.model.api.command.ContentException;
>> import org.eclipse.birt.report.model.api.command.NameException;
>> import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
>> import
>> org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
>> import org.eclipse.birt.report.model.api.metadata.IMetaDataDictiona ry;
>> import org.eclipse.birt.report.model.elements.interfaces.IReportIte mModel;
>> import org.eclipse.birt.report.model.elements.interfaces.IStyleMode l;
>>
>> import com.ibm.icu.util.ULocale;
>>
>> public class XMLReport
>> {
>>
>> ReportDesignHandle reportDesignHandle = null;
>>
>> ElementFactory elementFactory = null;
>>
>> IMetaDataDictionary dict = null;
>>
>> ComputedColumn cs1, cs2, cs3 = null;
>>
>> public static void main( String[] args ) throws SemanticException,
>> IOException
>> {
>> new XMLReport( ).createReport( );
>> }
>>
>> void createReport( ) throws SemanticException, IOException
>> {
>> //Configure the Engine and start the Platform
>> DesignConfig config = new DesignConfig( );
>>
>> config.setProperty("BIRT_HOME",
>> "C:/birt/birt-runtime-2_2_0/birt-runtime-2_2_0/ReportEngine");
>> IDesignEngine engine = null;
>> try{
>>
>>
>> Platform.startup( config );
>> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
>> .createFactoryObject(
>> IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
>> engine = factory.createDesignEngine( config );
>>
>> }catch( Exception ex){
>> ex.printStackTrace();
>> }
>>
>>
>> SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
>>
>>
>> // Create a new report
>> reportDesignHandle = session.createDesign( );
>>
>> // Element factory is used to create instances of BIRT elements.
>> elementFactory = reportDesignHandle.getElementFactory( );
>>
>> dict = new DesignEngine( null ).getMetaData( );
>>
>> createMasterPages( );
>> createDataSources( );
>> createDataSets( );
>> createBody( );
>>
>> String outputPath = "output";//$NON-NLS-1$
>> File outputFolder = new File( outputPath );
>> if ( !outputFolder.exists( ) && !outputFolder.mkdir( ) )
>> {
>> throw new IOException( "Can not create the output folder"
>> );//$NON-NLS-1$
>> }
>> reportDesignHandle.saveAs( "output/desample/XMLReport.rptdesign"
>> );//$NON-NLS-1$//$NON-NLS-2$
>> System.out.println("finished");
>> }
>>
>> //Scripted Data Set
>> /*
>> * private void createDataSources( ) throws SemanticException
>> {
>> ScriptDataSourceHandle dataSourceHandle =
>> elementFactory.newScriptDataSource( "Data Source" );//$NON-NLS-1$
>> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
>> }
>>
>> private void createDataSets( ) throws SemanticException
>> {
>> // Data Set
>> ScriptDataSetHandle dataSetHandle = elementFactory.newScriptDataSet(
>> "Data
>> Set" );//$NON-NLS-1$
>> dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$
>>
>> // Set open( ) in code
>> dataSetHandle.setOpen( "i=0;"//$NON-NLS-1$
>> + "sourcedata = new Array( new Array(3), new Array(3), new Array(3),
>> new Array(3));"//$NON-NLS-1$
>>
>> + "sourcedata[0][0] = 10; "//$NON-NLS-1$
>> + "sourcedata[0][1] = \"Ice Bella\";"//$NON-NLS-1$
>> + "sourcedata[0][2] = 304;"//$NON-NLS-1$
>>
>> + "sourcedata[1][0] = 10; "//$NON-NLS-1$
>> + "sourcedata[1][1] = \"Nola Dicci\";"//$NON-NLS-1$
>> + "sourcedata[1][2] = 258;"//$NON-NLS-1$
>>
>> + "sourcedata[2][0] = 11; "//$NON-NLS-1$
>> + "sourcedata[2][1] = \"Ice Bella\";"//$NON-NLS-1$
>> + "sourcedata[2][2] = 202;"//$NON-NLS-1$
>>
>> + "sourcedata[3][0] = 11; "//$NON-NLS-1$
>> + "sourcedata[3][1] = \"Nola Dicci\";"//$NON-NLS-1$
>> + "sourcedata[3][2] = 181;" );//$NON-NLS-1$
>>
>> // Set fetch( ) in code
>> dataSetHandle.setFetch( "if ( i < 4 ){"//$NON-NLS-1$
>> + "row[\"Month\"] = sourcedata[i][0];"//$NON-NLS-1$
>> + "row[\"Product\"] = sourcedata[i][1];"//$NON-NLS-1$
>> + "row[\"Amount\"] = sourcedata[i][2];"//$NON-NLS-1$
>> + "i++;"//$NON-NLS-1$
>> + "return true;}" + "else return false;" );//$NON-NLS-1$//$NON-NLS-2$
>>
>> // Set computed columns
>> cs1 = StructureFactory.createComputedColumn( );
>> cs1.setName( "Month" );//$NON-NLS-1$
>> cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
>> cs1.setDataType( "integer" );//$NON-NLS-1$
>>
>> cs2 = StructureFactory.createComputedColumn( );
>> cs2.setName( "Product" );//$NON-NLS-1$
>> cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
>> cs2.setDataType( "string" );//$NON-NLS-1$
>>
>> cs3 = StructureFactory.createComputedColumn( );
>> cs3.setName( "Amount" );//$NON-NLS-1$
>> cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
>> cs3.setDataType( "integer" );//$NON-NLS-1$
>>
>> PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
>> ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
>> computedSet.addItem( cs1 );
>> computedSet.addItem( cs2 );
>> computedSet.addItem( cs3 );
>>
>> reportDesignHandle.getDataSets( ).add( dataSetHandle );
>> }
>> */
>>
>>
>>
>> private void createDataSources( ) throws SemanticException
>> {
>> OdaDataSourceHandle dataSourceHandle =
>> elementFactory.newOdaDataSource("Data Source",
>> "org.eclipse.birt.report.data.oda.xml");
>> dataSourceHandle.setProperty("FILELIST", "C:/temp/xmltest.xml");
>> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
>> }
>>
>> private void createDataSets( ) throws SemanticException
>> {
>> // Data Set
>>
>> OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( "Data Set",
>> "org.eclipse.birt.report.data.oda.xml.dataSet" );
>> dsHandle.setDataSource( "Data Source" );
>> dsHandle.setQueryText(
>> " table0#-TNAME-#table0#:#[/people/person/name]#:#{name;String ;} " );
>>
>> reportDesignHandle.getDataSets( ).add( dsHandle );
>>
>>
>> }
>>
>> private void createMasterPages( ) throws ContentException, NameException
>> {
>> DesignElementHandle simpleMasterPage =
>> elementFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
>> reportDesignHandle.getMasterPages( ).add( simpleMasterPage );
>> }
>>
>>
>>
>> private void createBody( ) throws SemanticException
>> {
>>
>>
>>
>> TableHandle table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
>> table.setProperty( IStyleModel.TEXT_ALIGN_PROP,
>> DesignChoiceConstants.TEXT_ALIGN_CENTER );
>> table.setWidth( "80%" );//$NON-NLS-1$
>> table.setProperty( IReportItemModel.DATA_SET_PROP, "Data Set"
>> );//$NON-NLS-1$
>>
>> PropertyHandle computedSet = table.getColumnBindings( );
>> cs1 = StructureFactory.createComputedColumn( );
>>
>> cs1.setName("Name");
>> cs1.setExpression( "dataSetRow[\"name\"]" );//$NON-NLS-1$
>> computedSet.addItem( cs1 );
>>
>>
>>
>> // Header
>> RowHandle header = (RowHandle) table.getHeader( ).get( 0 );
>>
>> CellHandle tcell = (CellHandle) header.getCells( ).get( 0 );
>> LabelHandle label = elementFactory.newLabel( null );
>> label.setText( "Name" );//$NON-NLS-1$
>> tcell.getContent( ).add( label );
>>
>>
>>
>> DataItemHandle data = null;
>> // Detail
>> RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
>> tcell = (CellHandle) detail.getCells( ).get( 0 );
>> data = elementFactory.newDataItem( null );
>> data.setResultSetColumn( cs1.getName( ) );
>> tcell.getContent( ).add( data );
>>
>>
>> reportDesignHandle.getBody( ).add( table );
>>
>>
>> }
>>
>>
>> }
>>
>>
>> Jason Weathersby wrote:
>>> Can you post the entire routine or specify which line below is
>>> throwing the exception?
>>>
>>> Jason
>>>
>>> slezi wrote:
>>>> Hi,
>>>>
>>>> I don't know why this throws me NULLPointeException
>>>>
>>>> OdaDataSourceHandle dataSourceHandle =
>>>> elementFactory.newOdaDataSource("Data Source",
>>>> "org.eclipse.birt.report.data.oda.xml");
>>>>
>>>> I found this peace of code on the web and many more uses the same syntax
>>>> with some little differences like jdbc etc..
>>>>
>>>> Could you help me to fix it.
>>>>
>>>> exactly:
>>>> private void createDataSources()
>>>> {
>>>> try {
>>>> OdaDataSourceHandle dataSourceHandle;
>>>> dataSourceHandle =
>>>> elementFactory.newOdaDataSource("Data Source",
>>>> "org.eclipse.birt.report.data.oda.xml");
>>>> dataSourceHandle.setProperty("FILELIST",
>>>> "/home/slezi/workspace/rep/data/result-1180445164703.xml");
>>>>
>>>> designHandle.getDataSources().add(dataSourceHandle);
>>>> }
>>>> catch (SemanticException e) {
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>>
>>>> this is the exception it throws
>>>> java.lang.NullPointerException
>>>> at subreport.createDataSources(subreport.java:40)
>>>> at subreport.start(subreport.java:99)
>>>> at
>>>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>>
>>>> at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>>
>>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>> at
>>>> org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
>>>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
>>>> at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
>>>> at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Re: NULL Pointer Exception problem [message #252019 is a reply to message #251199] Fri, 10 August 2007 17:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: antonin.slezacek.cloudsmith.com

I really want to thank you for your help, your example helps me much.
But i've got a question, in your example there is method public static
main .. that mean that you are able to run it as a Java application,
because i have to implement IApplication and add start method for runnig
it like eclipse plugin. If you are able to run it simly like java app,
please note me down how. Thanks a lot.

Jason Weathersby napsal(a):
> Can you try the example I attached.
>
> Also in your example is elementFactory null?
> Is this the only Data Source in the report?
>
>
> Thanks
>
> Jason
>
> slezi wrote:
>> This line throws it
>>
>> OdaDataSourceHandle dataSourceHandle =
>> elementFactory.newOdaDataSource("Data Source",
>> "org.eclipse.birt.report.data.oda.xml");
>>
>>
>> Jason Weathersby napsal(a):
>>> Here is a working example of this:
>>>
>>> Jason
>>>
>>> XML File
>>> <people>
>>> <person>
>>> <name>Jonathan</name>
>>> <nicknames>
>>> <nickname>John</nickname>
>>> <nickname>Jon</nickname>
>>> </nicknames>
>>> </person>
>>> <person>
>>> <name>Steven</name>
>>> <nicknames>
>>> <nickname>Steve</nickname>
>>> </nicknames>
>>> </person>
>>> </people>
>>>
>>> Code
>>>
>>> import java.io.File;
>>> import java.io.IOException;
>>> import org.eclipse.birt.core.framework.Platform;
>>> import org.eclipse.birt.report.model.api.CellHandle;
>>> import org.eclipse.birt.report.model.api.DataItemHandle;
>>> import org.eclipse.birt.report.model.api.DesignConfig;
>>> import org.eclipse.birt.report.model.api.DesignElementHandle;
>>> import org.eclipse.birt.report.model.api.DesignEngine;
>>> import org.eclipse.birt.report.model.api.ElementFactory;
>>> import org.eclipse.birt.report.model.api.IDesignEngine;
>>> import org.eclipse.birt.report.model.api.IDesignEngineFactory;
>>> import org.eclipse.birt.report.model.api.LabelHandle;
>>> import org.eclipse.birt.report.model.api.PropertyHandle;
>>> import org.eclipse.birt.report.model.api.ReportDesignHandle;
>>> import org.eclipse.birt.report.model.api.RowHandle;
>>> import org.eclipse.birt.report.model.api.OdaDataSetHandle;
>>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>>> import org.eclipse.birt.report.model.api.SessionHandle;
>>> import org.eclipse.birt.report.model.api.StructureFactory;
>>> import org.eclipse.birt.report.model.api.TableHandle;
>>> import org.eclipse.birt.report.model.api.activity.SemanticException ;
>>> import org.eclipse.birt.report.model.api.command.ContentException;
>>> import org.eclipse.birt.report.model.api.command.NameException;
>>> import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
>>> import
>>> org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
>>> import org.eclipse.birt.report.model.api.metadata.IMetaDataDictiona ry;
>>> import
>>> org.eclipse.birt.report.model.elements.interfaces.IReportIte mModel;
>>> import org.eclipse.birt.report.model.elements.interfaces.IStyleMode l;
>>>
>>> import com.ibm.icu.util.ULocale;
>>>
>>> public class XMLReport
>>> {
>>>
>>> ReportDesignHandle reportDesignHandle = null;
>>>
>>> ElementFactory elementFactory = null;
>>>
>>> IMetaDataDictionary dict = null;
>>>
>>> ComputedColumn cs1, cs2, cs3 = null;
>>>
>>> public static void main( String[] args ) throws SemanticException,
>>> IOException
>>> {
>>> new XMLReport( ).createReport( );
>>> }
>>>
>>> void createReport( ) throws SemanticException, IOException
>>> {
>>> //Configure the Engine and start the Platform
>>> DesignConfig config = new DesignConfig( );
>>>
>>> config.setProperty("BIRT_HOME",
>>> "C:/birt/birt-runtime-2_2_0/birt-runtime-2_2_0/ReportEngine");
>>> IDesignEngine engine = null;
>>> try{
>>>
>>>
>>> Platform.startup( config );
>>> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
>>> .createFactoryObject(
>>> IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
>>> engine = factory.createDesignEngine( config );
>>>
>>> }catch( Exception ex){
>>> ex.printStackTrace();
>>> }
>>>
>>>
>>> SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
>>>
>>>
>>> // Create a new report
>>> reportDesignHandle = session.createDesign( );
>>>
>>> // Element factory is used to create instances of BIRT elements.
>>> elementFactory = reportDesignHandle.getElementFactory( );
>>>
>>> dict = new DesignEngine( null ).getMetaData( );
>>>
>>> createMasterPages( );
>>> createDataSources( );
>>> createDataSets( );
>>> createBody( );
>>>
>>> String outputPath = "output";//$NON-NLS-1$
>>> File outputFolder = new File( outputPath );
>>> if ( !outputFolder.exists( ) && !outputFolder.mkdir( ) )
>>> {
>>> throw new IOException( "Can not create the output folder"
>>> );//$NON-NLS-1$
>>> }
>>> reportDesignHandle.saveAs( "output/desample/XMLReport.rptdesign"
>>> );//$NON-NLS-1$//$NON-NLS-2$
>>> System.out.println("finished");
>>> }
>>>
>>> //Scripted Data Set
>>> /*
>>> * private void createDataSources( ) throws SemanticException
>>> {
>>> ScriptDataSourceHandle dataSourceHandle =
>>> elementFactory.newScriptDataSource( "Data Source" );//$NON-NLS-1$
>>> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
>>> }
>>>
>>> private void createDataSets( ) throws SemanticException
>>> {
>>> // Data Set
>>> ScriptDataSetHandle dataSetHandle = elementFactory.newScriptDataSet(
>>> "Data
>>> Set" );//$NON-NLS-1$
>>> dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$
>>>
>>> // Set open( ) in code
>>> dataSetHandle.setOpen( "i=0;"//$NON-NLS-1$
>>> + "sourcedata = new Array( new Array(3), new Array(3), new Array(3),
>>> new Array(3));"//$NON-NLS-1$
>>>
>>> + "sourcedata[0][0] = 10; "//$NON-NLS-1$
>>> + "sourcedata[0][1] = \"Ice Bella\";"//$NON-NLS-1$
>>> + "sourcedata[0][2] = 304;"//$NON-NLS-1$
>>>
>>> + "sourcedata[1][0] = 10; "//$NON-NLS-1$
>>> + "sourcedata[1][1] = \"Nola Dicci\";"//$NON-NLS-1$
>>> + "sourcedata[1][2] = 258;"//$NON-NLS-1$
>>>
>>> + "sourcedata[2][0] = 11; "//$NON-NLS-1$
>>> + "sourcedata[2][1] = \"Ice Bella\";"//$NON-NLS-1$
>>> + "sourcedata[2][2] = 202;"//$NON-NLS-1$
>>>
>>> + "sourcedata[3][0] = 11; "//$NON-NLS-1$
>>> + "sourcedata[3][1] = \"Nola Dicci\";"//$NON-NLS-1$
>>> + "sourcedata[3][2] = 181;" );//$NON-NLS-1$
>>>
>>> // Set fetch( ) in code
>>> dataSetHandle.setFetch( "if ( i < 4 ){"//$NON-NLS-1$
>>> + "row[\"Month\"] = sourcedata[i][0];"//$NON-NLS-1$
>>> + "row[\"Product\"] = sourcedata[i][1];"//$NON-NLS-1$
>>> + "row[\"Amount\"] = sourcedata[i][2];"//$NON-NLS-1$
>>> + "i++;"//$NON-NLS-1$
>>> + "return true;}" + "else return false;"
>>> );//$NON-NLS-1$//$NON-NLS-2$
>>>
>>> // Set computed columns
>>> cs1 = StructureFactory.createComputedColumn( );
>>> cs1.setName( "Month" );//$NON-NLS-1$
>>> cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
>>> cs1.setDataType( "integer" );//$NON-NLS-1$
>>>
>>> cs2 = StructureFactory.createComputedColumn( );
>>> cs2.setName( "Product" );//$NON-NLS-1$
>>> cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
>>> cs2.setDataType( "string" );//$NON-NLS-1$
>>>
>>> cs3 = StructureFactory.createComputedColumn( );
>>> cs3.setName( "Amount" );//$NON-NLS-1$
>>> cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
>>> cs3.setDataType( "integer" );//$NON-NLS-1$
>>>
>>> PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
>>> ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
>>> computedSet.addItem( cs1 );
>>> computedSet.addItem( cs2 );
>>> computedSet.addItem( cs3 );
>>>
>>> reportDesignHandle.getDataSets( ).add( dataSetHandle );
>>> }
>>> */
>>>
>>>
>>>
>>> private void createDataSources( ) throws SemanticException
>>> {
>>> OdaDataSourceHandle dataSourceHandle =
>>> elementFactory.newOdaDataSource("Data Source",
>>> "org.eclipse.birt.report.data.oda.xml");
>>> dataSourceHandle.setProperty("FILELIST", "C:/temp/xmltest.xml");
>>> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
>>> }
>>>
>>> private void createDataSets( ) throws SemanticException
>>> {
>>> // Data Set
>>>
>>> OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( "Data Set",
>>> "org.eclipse.birt.report.data.oda.xml.dataSet" );
>>> dsHandle.setDataSource( "Data Source" );
>>> dsHandle.setQueryText(
>>> " table0#-TNAME-#table0#:#[/people/person/name]#:#{name;String ;} " );
>>>
>>> reportDesignHandle.getDataSets( ).add( dsHandle );
>>>
>>>
>>> }
>>>
>>> private void createMasterPages( ) throws ContentException,
>>> NameException
>>> {
>>> DesignElementHandle simpleMasterPage =
>>> elementFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
>>> reportDesignHandle.getMasterPages( ).add( simpleMasterPage );
>>> }
>>>
>>>
>>>
>>> private void createBody( ) throws SemanticException
>>> {
>>>
>>>
>>>
>>> TableHandle table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
>>> table.setProperty( IStyleModel.TEXT_ALIGN_PROP,
>>> DesignChoiceConstants.TEXT_ALIGN_CENTER );
>>> table.setWidth( "80%" );//$NON-NLS-1$
>>> table.setProperty( IReportItemModel.DATA_SET_PROP, "Data Set"
>>> );//$NON-NLS-1$
>>>
>>> PropertyHandle computedSet = table.getColumnBindings( );
>>> cs1 = StructureFactory.createComputedColumn( );
>>>
>>> cs1.setName("Name");
>>> cs1.setExpression( "dataSetRow[\"name\"]" );//$NON-NLS-1$
>>> computedSet.addItem( cs1 );
>>>
>>>
>>>
>>> // Header
>>> RowHandle header = (RowHandle) table.getHeader( ).get( 0 );
>>>
>>> CellHandle tcell = (CellHandle) header.getCells( ).get( 0 );
>>> LabelHandle label = elementFactory.newLabel( null );
>>> label.setText( "Name" );//$NON-NLS-1$
>>> tcell.getContent( ).add( label );
>>>
>>>
>>>
>>> DataItemHandle data = null;
>>> // Detail
>>> RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
>>> tcell = (CellHandle) detail.getCells( ).get( 0 );
>>> data = elementFactory.newDataItem( null );
>>> data.setResultSetColumn( cs1.getName( ) );
>>> tcell.getContent( ).add( data );
>>>
>>>
>>> reportDesignHandle.getBody( ).add( table );
>>>
>>>
>>> }
>>>
>>>
>>> }
>>>
>>>
>>> Jason Weathersby wrote:
>>>> Can you post the entire routine or specify which line below is
>>>> throwing the exception?
>>>>
>>>> Jason
>>>>
>>>> slezi wrote:
>>>>> Hi,
>>>>>
>>>>> I don't know why this throws me NULLPointeException
>>>>>
>>>>> OdaDataSourceHandle dataSourceHandle =
>>>>> elementFactory.newOdaDataSource("Data Source",
>>>>> "org.eclipse.birt.report.data.oda.xml");
>>>>>
>>>>> I found this peace of code on the web and many more uses the same
>>>>> syntax
>>>>> with some little differences like jdbc etc..
>>>>>
>>>>> Could you help me to fix it.
>>>>>
>>>>> exactly:
>>>>> private void createDataSources()
>>>>> {
>>>>> try {
>>>>> OdaDataSourceHandle dataSourceHandle;
>>>>> dataSourceHandle =
>>>>> elementFactory.newOdaDataSource("Data Source",
>>>>> "org.eclipse.birt.report.data.oda.xml");
>>>>> dataSourceHandle.setProperty("FILELIST",
>>>>> "/home/slezi/workspace/rep/data/result-1180445164703.xml");
>>>>>
>>>>> designHandle.getDataSources().add(dataSourceHandle);
>>>>> }
>>>>> catch (SemanticException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>>
>>>>> this is the exception it throws
>>>>> java.lang.NullPointerException
>>>>> at subreport.createDataSources(subreport.java:40)
>>>>> at subreport.start(subreport.java:99)
>>>>> at
>>>>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
>>>>>
>>>>>
>>>>> at
>>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
>>>>>
>>>>>
>>>>> at
>>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
>>>>>
>>>>>
>>>>> at
>>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
>>>>>
>>>>>
>>>>> at
>>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
>>>>>
>>>>>
>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>> at
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>>>
>>>>>
>>>>> at
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>>>
>>>>>
>>>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>>> at
>>>>> org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
>>>>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
>>>>> at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
>>>>> at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Re: NULL Pointer Exception problem [message #252084 is a reply to message #252019] Fri, 10 August 2007 21:41 Go to previous message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Take a look at this page:
http://wiki.eclipse.org/RCP_Example

There are two examples one to show using the viewer in an rcp
application and one to show using the report engine api. Look at the
report engine api example. To use the design engine api will be very
similar.

Jason

slezi wrote:
> I really want to thank you for your help, your example helps me much.
> But i've got a question, in your example there is method public static
> main .. that mean that you are able to run it as a Java application,
> because i have to implement IApplication and add start method for runnig
> it like eclipse plugin. If you are able to run it simly like java app,
> please note me down how. Thanks a lot.
>
> Jason Weathersby napsal(a):
>> Can you try the example I attached.
>>
>> Also in your example is elementFactory null?
>> Is this the only Data Source in the report?
>>
>>
>> Thanks
>>
>> Jason
>>
>> slezi wrote:
>>> This line throws it
>>>
>>> OdaDataSourceHandle dataSourceHandle =
>>> elementFactory.newOdaDataSource("Data Source",
>>> "org.eclipse.birt.report.data.oda.xml");
>>>
>>>
>>> Jason Weathersby napsal(a):
>>>> Here is a working example of this:
>>>>
>>>> Jason
>>>>
>>>> XML File
>>>> <people>
>>>> <person>
>>>> <name>Jonathan</name>
>>>> <nicknames>
>>>> <nickname>John</nickname>
>>>> <nickname>Jon</nickname>
>>>> </nicknames>
>>>> </person>
>>>> <person>
>>>> <name>Steven</name>
>>>> <nicknames>
>>>> <nickname>Steve</nickname>
>>>> </nicknames>
>>>> </person>
>>>> </people>
>>>>
>>>> Code
>>>>
>>>> import java.io.File;
>>>> import java.io.IOException;
>>>> import org.eclipse.birt.core.framework.Platform;
>>>> import org.eclipse.birt.report.model.api.CellHandle;
>>>> import org.eclipse.birt.report.model.api.DataItemHandle;
>>>> import org.eclipse.birt.report.model.api.DesignConfig;
>>>> import org.eclipse.birt.report.model.api.DesignElementHandle;
>>>> import org.eclipse.birt.report.model.api.DesignEngine;
>>>> import org.eclipse.birt.report.model.api.ElementFactory;
>>>> import org.eclipse.birt.report.model.api.IDesignEngine;
>>>> import org.eclipse.birt.report.model.api.IDesignEngineFactory;
>>>> import org.eclipse.birt.report.model.api.LabelHandle;
>>>> import org.eclipse.birt.report.model.api.PropertyHandle;
>>>> import org.eclipse.birt.report.model.api.ReportDesignHandle;
>>>> import org.eclipse.birt.report.model.api.RowHandle;
>>>> import org.eclipse.birt.report.model.api.OdaDataSetHandle;
>>>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>>>> import org.eclipse.birt.report.model.api.SessionHandle;
>>>> import org.eclipse.birt.report.model.api.StructureFactory;
>>>> import org.eclipse.birt.report.model.api.TableHandle;
>>>> import org.eclipse.birt.report.model.api.activity.SemanticException ;
>>>> import org.eclipse.birt.report.model.api.command.ContentException;
>>>> import org.eclipse.birt.report.model.api.command.NameException;
>>>> import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
>>>> import
>>>> org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
>>>> import org.eclipse.birt.report.model.api.metadata.IMetaDataDictiona ry;
>>>> import
>>>> org.eclipse.birt.report.model.elements.interfaces.IReportIte mModel;
>>>> import org.eclipse.birt.report.model.elements.interfaces.IStyleMode l;
>>>>
>>>> import com.ibm.icu.util.ULocale;
>>>>
>>>> public class XMLReport
>>>> {
>>>>
>>>> ReportDesignHandle reportDesignHandle = null;
>>>>
>>>> ElementFactory elementFactory = null;
>>>>
>>>> IMetaDataDictionary dict = null;
>>>>
>>>> ComputedColumn cs1, cs2, cs3 = null;
>>>>
>>>> public static void main( String[] args ) throws SemanticException,
>>>> IOException
>>>> {
>>>> new XMLReport( ).createReport( );
>>>> }
>>>>
>>>> void createReport( ) throws SemanticException, IOException
>>>> {
>>>> //Configure the Engine and start the Platform
>>>> DesignConfig config = new DesignConfig( );
>>>>
>>>> config.setProperty("BIRT_HOME",
>>>> "C:/birt/birt-runtime-2_2_0/birt-runtime-2_2_0/ReportEngine");
>>>> IDesignEngine engine = null;
>>>> try{
>>>>
>>>>
>>>> Platform.startup( config );
>>>> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
>>>> .createFactoryObject(
>>>> IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
>>>> engine = factory.createDesignEngine( config );
>>>>
>>>> }catch( Exception ex){
>>>> ex.printStackTrace();
>>>> }
>>>>
>>>>
>>>> SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
>>>>
>>>>
>>>> // Create a new report
>>>> reportDesignHandle = session.createDesign( );
>>>>
>>>> // Element factory is used to create instances of BIRT elements.
>>>> elementFactory = reportDesignHandle.getElementFactory( );
>>>>
>>>> dict = new DesignEngine( null ).getMetaData( );
>>>>
>>>> createMasterPages( );
>>>> createDataSources( );
>>>> createDataSets( );
>>>> createBody( );
>>>>
>>>> String outputPath = "output";//$NON-NLS-1$
>>>> File outputFolder = new File( outputPath );
>>>> if ( !outputFolder.exists( ) && !outputFolder.mkdir( ) )
>>>> {
>>>> throw new IOException( "Can not create the output folder"
>>>> );//$NON-NLS-1$
>>>> }
>>>> reportDesignHandle.saveAs( "output/desample/XMLReport.rptdesign"
>>>> );//$NON-NLS-1$//$NON-NLS-2$
>>>> System.out.println("finished");
>>>> }
>>>>
>>>> //Scripted Data Set
>>>> /*
>>>> * private void createDataSources( ) throws SemanticException
>>>> {
>>>> ScriptDataSourceHandle dataSourceHandle =
>>>> elementFactory.newScriptDataSource( "Data Source" );//$NON-NLS-1$
>>>> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
>>>> }
>>>>
>>>> private void createDataSets( ) throws SemanticException
>>>> {
>>>> // Data Set
>>>> ScriptDataSetHandle dataSetHandle = elementFactory.newScriptDataSet(
>>>> "Data
>>>> Set" );//$NON-NLS-1$
>>>> dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$
>>>>
>>>> // Set open( ) in code
>>>> dataSetHandle.setOpen( "i=0;"//$NON-NLS-1$
>>>> + "sourcedata = new Array( new Array(3), new Array(3), new Array(3),
>>>> new Array(3));"//$NON-NLS-1$
>>>>
>>>> + "sourcedata[0][0] = 10; "//$NON-NLS-1$
>>>> + "sourcedata[0][1] = \"Ice Bella\";"//$NON-NLS-1$
>>>> + "sourcedata[0][2] = 304;"//$NON-NLS-1$
>>>>
>>>> + "sourcedata[1][0] = 10; "//$NON-NLS-1$
>>>> + "sourcedata[1][1] = \"Nola Dicci\";"//$NON-NLS-1$
>>>> + "sourcedata[1][2] = 258;"//$NON-NLS-1$
>>>>
>>>> + "sourcedata[2][0] = 11; "//$NON-NLS-1$
>>>> + "sourcedata[2][1] = \"Ice Bella\";"//$NON-NLS-1$
>>>> + "sourcedata[2][2] = 202;"//$NON-NLS-1$
>>>>
>>>> + "sourcedata[3][0] = 11; "//$NON-NLS-1$
>>>> + "sourcedata[3][1] = \"Nola Dicci\";"//$NON-NLS-1$
>>>> + "sourcedata[3][2] = 181;" );//$NON-NLS-1$
>>>>
>>>> // Set fetch( ) in code
>>>> dataSetHandle.setFetch( "if ( i < 4 ){"//$NON-NLS-1$
>>>> + "row[\"Month\"] = sourcedata[i][0];"//$NON-NLS-1$
>>>> + "row[\"Product\"] = sourcedata[i][1];"//$NON-NLS-1$
>>>> + "row[\"Amount\"] = sourcedata[i][2];"//$NON-NLS-1$
>>>> + "i++;"//$NON-NLS-1$
>>>> + "return true;}" + "else return false;"
>>>> );//$NON-NLS-1$//$NON-NLS-2$
>>>>
>>>> // Set computed columns
>>>> cs1 = StructureFactory.createComputedColumn( );
>>>> cs1.setName( "Month" );//$NON-NLS-1$
>>>> cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
>>>> cs1.setDataType( "integer" );//$NON-NLS-1$
>>>>
>>>> cs2 = StructureFactory.createComputedColumn( );
>>>> cs2.setName( "Product" );//$NON-NLS-1$
>>>> cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
>>>> cs2.setDataType( "string" );//$NON-NLS-1$
>>>>
>>>> cs3 = StructureFactory.createComputedColumn( );
>>>> cs3.setName( "Amount" );//$NON-NLS-1$
>>>> cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
>>>> cs3.setDataType( "integer" );//$NON-NLS-1$
>>>>
>>>> PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
>>>> ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
>>>> computedSet.addItem( cs1 );
>>>> computedSet.addItem( cs2 );
>>>> computedSet.addItem( cs3 );
>>>>
>>>> reportDesignHandle.getDataSets( ).add( dataSetHandle );
>>>> }
>>>> */
>>>>
>>>>
>>>>
>>>> private void createDataSources( ) throws SemanticException
>>>> {
>>>> OdaDataSourceHandle dataSourceHandle =
>>>> elementFactory.newOdaDataSource("Data Source",
>>>> "org.eclipse.birt.report.data.oda.xml");
>>>> dataSourceHandle.setProperty("FILELIST", "C:/temp/xmltest.xml");
>>>> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
>>>> }
>>>>
>>>> private void createDataSets( ) throws SemanticException
>>>> {
>>>> // Data Set
>>>>
>>>> OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( "Data Set",
>>>> "org.eclipse.birt.report.data.oda.xml.dataSet" );
>>>> dsHandle.setDataSource( "Data Source" );
>>>> dsHandle.setQueryText(
>>>> " table0#-TNAME-#table0#:#[/people/person/name]#:#{name;String ;} " );
>>>>
>>>> reportDesignHandle.getDataSets( ).add( dsHandle );
>>>>
>>>>
>>>> }
>>>>
>>>> private void createMasterPages( ) throws ContentException,
>>>> NameException
>>>> {
>>>> DesignElementHandle simpleMasterPage =
>>>> elementFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
>>>> reportDesignHandle.getMasterPages( ).add( simpleMasterPage );
>>>> }
>>>>
>>>>
>>>>
>>>> private void createBody( ) throws SemanticException
>>>> {
>>>>
>>>>
>>>>
>>>> TableHandle table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
>>>> table.setProperty( IStyleModel.TEXT_ALIGN_PROP,
>>>> DesignChoiceConstants.TEXT_ALIGN_CENTER );
>>>> table.setWidth( "80%" );//$NON-NLS-1$
>>>> table.setProperty( IReportItemModel.DATA_SET_PROP, "Data Set"
>>>> );//$NON-NLS-1$
>>>>
>>>> PropertyHandle computedSet = table.getColumnBindings( );
>>>> cs1 = StructureFactory.createComputedColumn( );
>>>>
>>>> cs1.setName("Name");
>>>> cs1.setExpression( "dataSetRow[\"name\"]" );//$NON-NLS-1$
>>>> computedSet.addItem( cs1 );
>>>>
>>>>
>>>>
>>>> // Header
>>>> RowHandle header = (RowHandle) table.getHeader( ).get( 0 );
>>>>
>>>> CellHandle tcell = (CellHandle) header.getCells( ).get( 0 );
>>>> LabelHandle label = elementFactory.newLabel( null );
>>>> label.setText( "Name" );//$NON-NLS-1$
>>>> tcell.getContent( ).add( label );
>>>>
>>>>
>>>>
>>>> DataItemHandle data = null;
>>>> // Detail
>>>> RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
>>>> tcell = (CellHandle) detail.getCells( ).get( 0 );
>>>> data = elementFactory.newDataItem( null );
>>>> data.setResultSetColumn( cs1.getName( ) );
>>>> tcell.getContent( ).add( data );
>>>>
>>>>
>>>> reportDesignHandle.getBody( ).add( table );
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>> Jason Weathersby wrote:
>>>>> Can you post the entire routine or specify which line below is
>>>>> throwing the exception?
>>>>>
>>>>> Jason
>>>>>
>>>>> slezi wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I don't know why this throws me NULLPointeException
>>>>>>
>>>>>> OdaDataSourceHandle dataSourceHandle =
>>>>>> elementFactory.newOdaDataSource("Data Source",
>>>>>> "org.eclipse.birt.report.data.oda.xml");
>>>>>>
>>>>>> I found this peace of code on the web and many more uses the same
>>>>>> syntax
>>>>>> with some little differences like jdbc etc..
>>>>>>
>>>>>> Could you help me to fix it.
>>>>>>
>>>>>> exactly:
>>>>>> private void createDataSources()
>>>>>> {
>>>>>> try {
>>>>>> OdaDataSourceHandle dataSourceHandle;
>>>>>> dataSourceHandle =
>>>>>> elementFactory.newOdaDataSource("Data Source",
>>>>>> "org.eclipse.birt.report.data.oda.xml");
>>>>>> dataSourceHandle.setProperty("FILELIST",
>>>>>> "/home/slezi/workspace/rep/data/result-1180445164703.xml");
>>>>>>
>>>>>> designHandle.getDataSources().add(dataSourceHandle);
>>>>>> }
>>>>>> catch (SemanticException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> this is the exception it throws
>>>>>> java.lang.NullPointerException
>>>>>> at subreport.createDataSources(subreport.java:40)
>>>>>> at subreport.start(subreport.java:99)
>>>>>> at
>>>>>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
>>>>>>
>>>>>>
>>>>>> at
>>>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
>>>>>>
>>>>>>
>>>>>> at
>>>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
>>>>>>
>>>>>>
>>>>>> at
>>>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
>>>>>>
>>>>>>
>>>>>> at
>>>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
>>>>>>
>>>>>>
>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>>> at
>>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>>>>
>>>>>>
>>>>>> at
>>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>>>>
>>>>>>
>>>>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>>>> at
>>>>>> org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
>>>>>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
>>>>>> at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
>>>>>> at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Previous Topic:Making reports run in 2.1.0 and 2.1.3
Next Topic:invalid table filter in 2.1.3
Goto Forum:
  


Current Time: Thu Aug 29 12:44:05 GMT 2024

Powered by FUDForum. Page generated in 0.04315 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top