Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » NullPointerException in buildDataSource
NullPointerException in buildDataSource [message #198331] Mon, 30 October 2006 14:51 Go to next message
Eclipse UserFriend
Originally posted by: mauricio.sag.com.br

Hi

I am trying to use to create the DataSource as in the example:
http://wiki.eclipse.org/index.php/Dynamic_Table

But this occurring the following error:
java.lang.NullPointerException
at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)

This is the code that I am using:
164 public void buildDataSource() throws SemanticException {
165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
167 dsHandle.setProperty("odaDriverClass", "org.firebirdsql.jdbc.FBDriver");

....


Somebody could help me?

Debtor for the attention.
Re: NullPointerException in buildDataSource [message #198484 is a reply to message #198331] Tue, 31 October 2006 20:04 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Does this driver exist in the drivers directory?
org.firebirdsql.jdbc.FBDriver

Jason

"M.c.P." <mauricio@sag.com.br> wrote in message
news:ei53gl$l3j$1@utils.eclipse.org...
> Hi
>
> I am trying to use to create the DataSource as in the example:
> http://wiki.eclipse.org/index.php/Dynamic_Table
>
> But this occurring the following error:
> java.lang.NullPointerException
> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>
> This is the code that I am using:
> 164 public void buildDataSource() throws SemanticException {
> 165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
> 167 dsHandle.setProperty("odaDriverClass",
> "org.firebirdsql.jdbc.FBDriver");
>
> ...
>
>
> Somebody could help me?
>
> Debtor for the attention.
Re: NullPointerException in buildDataSource [message #198579 is a reply to message #198484] Tue, 31 October 2006 23:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: home4slc.pacbell.net

Hi,

I was trying to run this example as well and I am using the code that is
on the wiki (the standard oda driver class, not Firebird.)

I've been trying to debug this - I'm new to BIRT so I apologize ahead of
time if some of the below is obvious to folks, but if someone could
explain what is happening to help me learn, I'd be most appreciative.

I'm getting a NullPointerException at this line in the
DECreateDynamicTable.java code;

dsHandle = designFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );

It appears to me that in the newOdaDataSource method of
org.eclipse.birt.report.model.api.ElementFactory.java
that this line of code is returning null;

if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
extensionID ) == null )

from there it appears that the instance of ODAProviderFactory is being
creataed, but the NullPointerException is occuring when the
createODAProvider method is being called.

The createODAProvider method relies on the baseFactory variable, an
IODAProviderFactory being initialized via the initeTheFactory method
being called.

The only place I can see where this method is called is in
org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try to
debug the program it never appears to be called.

So, if what I have said above is correct, what calls the ModelPlugin's
start method, which is where the initeTheFactory method is called?

Also, if this is a bug I'd be happy to log it in bugzilla, just let me
know please.

I'm using BIRT 2.1.1.

Regards,

Susan



Jason Weathersby wrote:
> Does this driver exist in the drivers directory?
> org.firebirdsql.jdbc.FBDriver
>
> Jason
>
> "M.c.P." <mauricio@sag.com.br> wrote in message
> news:ei53gl$l3j$1@utils.eclipse.org...
>
>>Hi
>>
>>I am trying to use to create the DataSource as in the example:
>>http://wiki.eclipse.org/index.php/Dynamic_Table
>>
>>But this occurring the following error:
>>java.lang.NullPointerException
>>at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>
>>This is the code that I am using:
>>164 public void buildDataSource() throws SemanticException {
>>165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>>166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>167 dsHandle.setProperty("odaDriverClass",
>>"org.firebirdsql.jdbc.FBDriver");
>>
>>...
>>
>>
>>Somebody could help me?
>>
>>Debtor for the attention.
>
>
>
Re: NullPointerException in buildDataSource [message #198611 is a reply to message #198484] Wed, 01 November 2006 11:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauricio.sag.com.br

yes, i use it in the connection of my application.


Jason Weathersby escreveu:
> Does this driver exist in the drivers directory?
> org.firebirdsql.jdbc.FBDriver
>
> Jason
>
> "M.c.P." <mauricio@sag.com.br> wrote in message
> news:ei53gl$l3j$1@utils.eclipse.org...
>> Hi
>>
>> I am trying to use to create the DataSource as in the example:
>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>
>> But this occurring the following error:
>> java.lang.NullPointerException
>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>
>> This is the code that I am using:
>> 164 public void buildDataSource() throws SemanticException {
>> 165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>> 167 dsHandle.setProperty("odaDriverClass",
>> "org.firebirdsql.jdbc.FBDriver");
>>
>> ...
>>
>>
>> Somebody could help me?
>>
>> Debtor for the attention.
>
>
Re: NullPointerException in buildDataSource [message #198619 is a reply to message #198579] Wed, 01 November 2006 12:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauricio.sag.com.br

I already wrote this in bugzila:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877

Thanks!

Susan Cline escreveu:
> Hi,
>
> I was trying to run this example as well and I am using the code that is
> on the wiki (the standard oda driver class, not Firebird.)
>
> I've been trying to debug this - I'm new to BIRT so I apologize ahead of
> time if some of the below is obvious to folks, but if someone could
> explain what is happening to help me learn, I'd be most appreciative.
>
> I'm getting a NullPointerException at this line in the
> DECreateDynamicTable.java code;
>
> dsHandle = designFactory.newOdaDataSource(
> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
>
> It appears to me that in the newOdaDataSource method of
> org.eclipse.birt.report.model.api.ElementFactory.java
> that this line of code is returning null;
>
> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
> extensionID ) == null )
>
> from there it appears that the instance of ODAProviderFactory is being
> creataed, but the NullPointerException is occuring when the
> createODAProvider method is being called.
>
> The createODAProvider method relies on the baseFactory variable, an
> IODAProviderFactory being initialized via the initeTheFactory method
> being called.
>
> The only place I can see where this method is called is in
> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try to
> debug the program it never appears to be called.
>
> So, if what I have said above is correct, what calls the ModelPlugin's
> start method, which is where the initeTheFactory method is called?
>
> Also, if this is a bug I'd be happy to log it in bugzilla, just let me
> know please.
>
> I'm using BIRT 2.1.1.
>
> Regards,
>
> Susan
>
>
>
> Jason Weathersby wrote:
>> Does this driver exist in the drivers directory?
>> org.firebirdsql.jdbc.FBDriver
>>
>> Jason
>>
>> "M.c.P." <mauricio@sag.com.br> wrote in message
>> news:ei53gl$l3j$1@utils.eclipse.org...
>>
>>> Hi
>>>
>>> I am trying to use to create the DataSource as in the example:
>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>
>>> But this occurring the following error:
>>> java.lang.NullPointerException
>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>
>>> This is the code that I am using:
>>> 164 public void buildDataSource() throws SemanticException {
>>> 165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>> 167 dsHandle.setProperty("odaDriverClass",
>>> "org.firebirdsql.jdbc.FBDriver");
>>>
>>> ...
>>>
>>>
>>> Somebody could help me?
>>>
>>> Debtor for the attention.
>>
>>
>>
Re: NullPointerException in buildDataSource [message #198808 is a reply to message #198619] Thu, 02 November 2006 20:03 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

What are you setting your BIRT HOME to?

Jason

"M.c.P." <mauricio@sag.com.br> wrote in message
news:eia3tf$eca$1@utils.eclipse.org...
>I already wrote this in bugzila:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>
> Thanks!
>
> Susan Cline escreveu:
>> Hi,
>>
>> I was trying to run this example as well and I am using the code that is
>> on the wiki (the standard oda driver class, not Firebird.)
>>
>> I've been trying to debug this - I'm new to BIRT so I apologize ahead of
>> time if some of the below is obvious to folks, but if someone could
>> explain what is happening to help me learn, I'd be most appreciative.
>>
>> I'm getting a NullPointerException at this line in the
>> DECreateDynamicTable.java code;
>>
>> dsHandle = designFactory.newOdaDataSource(
>> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
>>
>> It appears to me that in the newOdaDataSource method of
>> org.eclipse.birt.report.model.api.ElementFactory.java
>> that this line of code is returning null;
>>
>> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>> extensionID ) == null )
>>
>> from there it appears that the instance of ODAProviderFactory is being
>> creataed, but the NullPointerException is occuring when the
>> createODAProvider method is being called.
>>
>> The createODAProvider method relies on the baseFactory variable, an
>> IODAProviderFactory being initialized via the initeTheFactory method
>> being called.
>>
>> The only place I can see where this method is called is in
>> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try to debug
>> the program it never appears to be called.
>>
>> So, if what I have said above is correct, what calls the ModelPlugin's
>> start method, which is where the initeTheFactory method is called?
>>
>> Also, if this is a bug I'd be happy to log it in bugzilla, just let me
>> know please.
>>
>> I'm using BIRT 2.1.1.
>>
>> Regards,
>>
>> Susan
>>
>>
>>
>> Jason Weathersby wrote:
>>> Does this driver exist in the drivers directory?
>>> org.firebirdsql.jdbc.FBDriver
>>>
>>> Jason
>>>
>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>> news:ei53gl$l3j$1@utils.eclipse.org...
>>>
>>>> Hi
>>>>
>>>> I am trying to use to create the DataSource as in the example:
>>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>
>>>> But this occurring the following error:
>>>> java.lang.NullPointerException
>>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>
>>>> This is the code that I am using:
>>>> 164 public void buildDataSource() throws SemanticException {
>>>> 165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>> 167 dsHandle.setProperty("odaDriverClass",
>>>> "org.firebirdsql.jdbc.FBDriver");
>>>>
>>>> ...
>>>>
>>>>
>>>> Somebody could help me?
>>>>
>>>> Debtor for the attention.
>>>
>>>
>>>
Re: NullPointerException in buildDataSource [message #198914 is a reply to message #198808] Fri, 03 November 2006 01:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: home4slc.pacbell.net

This is a multi-part message in MIME format.
--------------080608010400090506050803
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi Jason,

Regarding BIRT_HOME the first time I ran the example I figured out this
needed to be set, however, I am pointing only to the runtime. Does it
need to point to the full BIRT eclipse install?

I will make comments to the wiki page after I get it running, because I
believe the instructions can be improved upon for others.

Here is my BIRT_HOME:

config.setProperty("BIRT_HOME",
"C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine");

C:\Documents and Settings\Administrator>dir
C:\projects\BIRT\downloads\birt-runt
ime-2_1_1\ReportEngine
Volume in drive C has no label.
Volume Serial Number is 8017-F8A8

Directory of C:\projects\BIRT\downloads\birt-runtime-2_1_1\ReportEngine

10/31/2006 03:40 PM <DIR> .
10/31/2006 03:40 PM <DIR> ..
10/31/2006 03:40 PM <DIR> configuration
09/26/2006 10:44 AM 1,485 genReport.bat
09/26/2006 10:44 AM 1,105 genReport.sh
10/16/2006 11:08 AM <DIR> lib
10/16/2006 11:09 AM <DIR> plugins
10/16/2006 11:08 AM <DIR> samples
10/31/2006 11:45 AM <DIR> workspace
2 File(s) 2,590 bytes
7 Dir(s) 58,010,800,128 bytes free

Which plugin do you suspect is not being found? If it is the plugin
containing ModelPlugin.class, I checked under the BIRT_HOME/plugins
directory and found the
org.eclipse.birt.report.model_2.1.1V20060926-0959.jar file which
contains this class.

I've attached my java class for you to look at and see if you find
anything else if the setting I have for BIRT_HOME is correct.

Also, I did run the SimpleCreate.java program and it ran successfully,
although I realize the second example is more complicated - but at least
my BIRT_HOME was set correctly for the first example.

Regards,

Susan


Jason Weathersby wrote:

> What are you setting your BIRT HOME to?
>
> Jason
>
> "M.c.P." <mauricio@sag.com.br> wrote in message
> news:eia3tf$eca$1@utils.eclipse.org...
>
>>I already wrote this in bugzila:
>>https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>>
>>Thanks!
>>
>>Susan Cline escreveu:
>>
>>>Hi,
>>>
>>>I was trying to run this example as well and I am using the code that is
>>>on the wiki (the standard oda driver class, not Firebird.)
>>>
>>>I've been trying to debug this - I'm new to BIRT so I apologize ahead of
>>>time if some of the below is obvious to folks, but if someone could
>>>explain what is happening to help me learn, I'd be most appreciative.
>>>
>>>I'm getting a NullPointerException at this line in the
>>>DECreateDynamicTable.java code;
>>>
>>>dsHandle = designFactory.newOdaDataSource(
>>> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
>>>
>>>It appears to me that in the newOdaDataSource method of
>>>org.eclipse.birt.report.model.api.ElementFactory.java
>>>that this line of code is returning null;
>>>
>>>if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>>> extensionID ) == null )
>>>
>>>from there it appears that the instance of ODAProviderFactory is being
>>>creataed, but the NullPointerException is occuring when the
>>>createODAProvider method is being called.
>>>
>>>The createODAProvider method relies on the baseFactory variable, an
>>>IODAProviderFactory being initialized via the initeTheFactory method
>>>being called.
>>>
>>>The only place I can see where this method is called is in
>>>org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try to debug
>>>the program it never appears to be called.
>>>
>>>So, if what I have said above is correct, what calls the ModelPlugin's
>>>start method, which is where the initeTheFactory method is called?
>>>
>>>Also, if this is a bug I'd be happy to log it in bugzilla, just let me
>>>know please.
>>>
>>>I'm using BIRT 2.1.1.
>>>
>>>Regards,
>>>
>>>Susan
>>>
>>>
>>>
>>>Jason Weathersby wrote:
>>>
>>>>Does this driver exist in the drivers directory?
>>>>org.firebirdsql.jdbc.FBDriver
>>>>
>>>>Jason
>>>>
>>>>"M.c.P." <mauricio@sag.com.br> wrote in message
>>>>news:ei53gl$l3j$1@utils.eclipse.org...
>>>>
>>>>
>>>>>Hi
>>>>>
>>>>>I am trying to use to create the DataSource as in the example:
>>>>>http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>>
>>>>>But this occurring the following error:
>>>>>java.lang.NullPointerException
>>>>>at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>>
>>>>>This is the code that I am using:
>>>>>164 public void buildDataSource() throws SemanticException {
>>>>>165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>>>>>166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>>>167 dsHandle.setProperty("odaDriverClass",
>>>>>"org.firebirdsql.jdbc.FBDriver");
>>>>>
>>>>>...
>>>>>
>>>>>
>>>>>Somebody could help me?
>>>>>
>>>>>Debtor for the attention.
>>>>
>>>>
>>>>
>
>


--------------080608010400090506050803
Content-Type: text/plain;
name="DECreateDynamicTable.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="DECreateDynamicTable.java"

import java.io.IOException;
import java.util.ArrayList;

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.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.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
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.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.elements.structures.Comput edColumn;

import com.ibm.icu.util.ULocale;

/**
* Dynamic Table BIRT Design Engine API (DEAPI) demo.
*/

public class DECreateDynamicTable
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;

public static void main( String[] args )
{
try
{
DECreateDynamicTable de = new DECreateDynamicTable();
ArrayList al = new ArrayList();
al.add("OFFICECODE");
al.add("CITY");
al.add("COUNTRY");

de.buildReport(al, "From Offices" );
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

void buildDataSource( ) throws SemanticException
{
OdaDataSourceHandle dsHandle = null;
System.out.println("designFactory is " + designFactory.toString());
dsHandle = designFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
System.out.println("dsHandle is " + dsHandle.toString());
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );

designHandle.getDataSources( ).add( dsHandle );

}

void buildDataSet(ArrayList cols, String fromClause ) throws SemanticException
{

OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select ";
for( int i=0; i < cols.size(); i++){
qry += " " + cols.get(i);
if( i != (cols.size() -1) ){
qry += ",";
}

}
qry += " " + fromClause;

dsHandle.setQueryText( qry );

designHandle.getDataSets( ).add( dsHandle );



}
void buildReport(ArrayList cols, String fromClause ) throws IOException, SemanticException
{


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

config.setProperty("BIRT_HOME", "C:/projects/BIRT/downloads/birt-runtime-2_1_1/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();
}


try{
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
//open a design or a template
designHandle = session.openDesign("c:/temp/hello_world.rptdesign");
designFactory = designHandle.getElementFactory( );
}
catch (Exception e){
e.printStackTrace();
System.exit(0);
}
try {
//designFactory = designHandle.getElementFactory( );

buildDataSource();
buildDataSet(cols, fromClause);

TableHandle table = designFactory.newTableItem( "table", cols.size() );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ds" ) );


PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;

for( int i=0; i < cols.size(); i++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols.get(i));
cs1.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]");
computedSet.addItem(cs1);
}


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


for( int i=0; i < cols.size(); i++){
LabelHandle label1 = designFactory.newLabel( (String)cols.get(i) );
label1.setText((String)cols.get(i));
CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
cell.getContent( ).add( label1 );
}

// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for( int i=0; i < cols.size(); i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols.get(i) );
data.setResultSetColumn( (String)cols.get(i));
cell.getContent( ).add( data );
}

designHandle.getBody( ).add( table );

// Save the design and close it.

designHandle.saveAs( "c:/temp/sample.rptdesign" ); //$NON-NLS-1$
designHandle.close( );
System.out.println("Finished");
}catch (Exception e){
e.printStackTrace();
}

}
}

--------------080608010400090506050803--
Re: NullPointerException in buildDataSource [message #198964 is a reply to message #198914] Fri, 03 November 2006 11:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauricio.sag.com.br

Hi.
I also twirled the first example (SimpleCreate.java) and I functioned
correctly.
Mine birt home is this: config.setProperty (“BIRT_HOME”, “C:
/birtruntime/birt-runtime-2_1_1/ReportEngine”);

It will be that it is problem in BIRT_HOME?



Susan L. Cline escreveu:
> Hi Jason,
>
> Regarding BIRT_HOME the first time I ran the example I figured out this
> needed to be set, however, I am pointing only to the runtime. Does it
> need to point to the full BIRT eclipse install?
>
> I will make comments to the wiki page after I get it running, because I
> believe the instructions can be improved upon for others.
>
> Here is my BIRT_HOME:
>
> config.setProperty("BIRT_HOME",
> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine");
>
> C:\Documents and Settings\Administrator>dir
> C:\projects\BIRT\downloads\birt-runt
> ime-2_1_1\ReportEngine
> Volume in drive C has no label.
> Volume Serial Number is 8017-F8A8
>
> Directory of C:\projects\BIRT\downloads\birt-runtime-2_1_1\ReportEngine
>
> 10/31/2006 03:40 PM <DIR> .
> 10/31/2006 03:40 PM <DIR> ..
> 10/31/2006 03:40 PM <DIR> configuration
> 09/26/2006 10:44 AM 1,485 genReport.bat
> 09/26/2006 10:44 AM 1,105 genReport.sh
> 10/16/2006 11:08 AM <DIR> lib
> 10/16/2006 11:09 AM <DIR> plugins
> 10/16/2006 11:08 AM <DIR> samples
> 10/31/2006 11:45 AM <DIR> workspace
> 2 File(s) 2,590 bytes
> 7 Dir(s) 58,010,800,128 bytes free
>
> Which plugin do you suspect is not being found? If it is the plugin
> containing ModelPlugin.class, I checked under the BIRT_HOME/plugins
> directory and found the
> org.eclipse.birt.report.model_2.1.1V20060926-0959.jar file which
> contains this class.
>
> I've attached my java class for you to look at and see if you find
> anything else if the setting I have for BIRT_HOME is correct.
>
> Also, I did run the SimpleCreate.java program and it ran successfully,
> although I realize the second example is more complicated - but at least
> my BIRT_HOME was set correctly for the first example.
>
> Regards,
>
> Susan
>
>
> Jason Weathersby wrote:
>
>> What are you setting your BIRT HOME to?
>>
>> Jason
>>
>> "M.c.P." <mauricio@sag.com.br> wrote in message
>> news:eia3tf$eca$1@utils.eclipse.org...
>>
>>> I already wrote this in bugzila:
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>>>
>>> Thanks!
>>>
>>> Susan Cline escreveu:
>>>
>>>> Hi,
>>>>
>>>> I was trying to run this example as well and I am using the code
>>>> that is on the wiki (the standard oda driver class, not Firebird.)
>>>>
>>>> I've been trying to debug this - I'm new to BIRT so I apologize
>>>> ahead of time if some of the below is obvious to folks, but if
>>>> someone could explain what is happening to help me learn, I'd be
>>>> most appreciative.
>>>>
>>>> I'm getting a NullPointerException at this line in the
>>>> DECreateDynamicTable.java code;
>>>>
>>>> dsHandle = designFactory.newOdaDataSource(
>>>> "Data Source",
>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>
>>>> It appears to me that in the newOdaDataSource method of
>>>> org.eclipse.birt.report.model.api.ElementFactory.java
>>>> that this line of code is returning null;
>>>>
>>>> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>>>> extensionID ) == null )
>>>>
>>>> from there it appears that the instance of ODAProviderFactory is
>>>> being creataed, but the NullPointerException is occuring when the
>>>> createODAProvider method is being called.
>>>>
>>>> The createODAProvider method relies on the baseFactory variable, an
>>>> IODAProviderFactory being initialized via the initeTheFactory method
>>>> being called.
>>>>
>>>> The only place I can see where this method is called is in
>>>> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try to
>>>> debug the program it never appears to be called.
>>>>
>>>> So, if what I have said above is correct, what calls the
>>>> ModelPlugin's start method, which is where the initeTheFactory
>>>> method is called?
>>>>
>>>> Also, if this is a bug I'd be happy to log it in bugzilla, just let
>>>> me know please.
>>>>
>>>> I'm using BIRT 2.1.1.
>>>>
>>>> Regards,
>>>>
>>>> Susan
>>>>
>>>>
>>>>
>>>> Jason Weathersby wrote:
>>>>
>>>>> Does this driver exist in the drivers directory?
>>>>> org.firebirdsql.jdbc.FBDriver
>>>>>
>>>>> Jason
>>>>>
>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>> news:ei53gl$l3j$1@utils.eclipse.org...
>>>>>
>>>>>
>>>>>> Hi
>>>>>>
>>>>>> I am trying to use to create the DataSource as in the example:
>>>>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>>>
>>>>>> But this occurring the following error:
>>>>>> java.lang.NullPointerException
>>>>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>>>
>>>>>> This is the code that I am using:
>>>>>> 164 public void buildDataSource() throws SemanticException {
>>>>>> 165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>>>>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>>>> 167 dsHandle.setProperty("odaDriverClass",
>>>>>> "org.firebirdsql.jdbc.FBDriver");
>>>>>>
>>>>>> ...
>>>>>>
>>>>>>
>>>>>> Somebody could help me?
>>>>>>
>>>>>> Debtor for the attention.
>>>>>
>>>>>
>>>>>
>>
>>
>
>
> ------------------------------------------------------------ ------------
>
> import java.io.IOException;
> import java.util.ArrayList;
>
> 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.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.OdaDataSetHandle;
> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
> 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.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.elements.structures.Comput edColumn;
>
> import com.ibm.icu.util.ULocale;
>
> /**
> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
> */
>
> public class DECreateDynamicTable
> {
> ReportDesignHandle designHandle = null;
> ElementFactory designFactory = null;
> StructureFactory structFactory = null;
>
> public static void main( String[] args )
> {
> try
> {
> DECreateDynamicTable de = new DECreateDynamicTable();
> ArrayList al = new ArrayList();
> al.add("OFFICECODE");
> al.add("CITY");
> al.add("COUNTRY");
>
> de.buildReport(al, "From Offices" );
> }
> catch ( IOException e )
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch ( SemanticException e )
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> void buildDataSource( ) throws SemanticException
> {
> OdaDataSourceHandle dsHandle = null;
> System.out.println("designFactory is " + designFactory.toString());
> dsHandle = designFactory.newOdaDataSource(
> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
> System.out.println("dsHandle is " + dsHandle.toString());
> dsHandle.setProperty( "odaDriverClass",
> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
> dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
> dsHandle.setProperty( "odaUser", "ClassicModels" );
> dsHandle.setProperty( "odaPassword", "" );
>
> designHandle.getDataSources( ).add( dsHandle );
>
> }
>
> void buildDataSet(ArrayList cols, String fromClause ) throws SemanticException
> {
>
> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
> dsHandle.setDataSource( "Data Source" );
> String qry = "Select ";
> for( int i=0; i < cols.size(); i++){
> qry += " " + cols.get(i);
> if( i != (cols.size() -1) ){
> qry += ",";
> }
>
> }
> qry += " " + fromClause;
>
> dsHandle.setQueryText( qry );
>
> designHandle.getDataSets( ).add( dsHandle );
>
>
>
> }
> void buildReport(ArrayList cols, String fromClause ) throws IOException, SemanticException
> {
>
>
> //Configure the Engine and start the Platform
> DesignConfig config = new DesignConfig( );
>
> config.setProperty("BIRT_HOME", "C:/projects/BIRT/downloads/birt-runtime-2_1_1/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();
> }
>
>
> try{
> SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
> //open a design or a template
> designHandle = session.openDesign("c:/temp/hello_world.rptdesign");
> designFactory = designHandle.getElementFactory( );
> }
> catch (Exception e){
> e.printStackTrace();
> System.exit(0);
> }
> try {
> //designFactory = designHandle.getElementFactory( );
>
> buildDataSource();
> buildDataSet(cols, fromClause);
>
> TableHandle table = designFactory.newTableItem( "table", cols.size() );
> table.setWidth( "100%" );
> table.setDataSet( designHandle.findDataSet( "ds" ) );
>
>
> PropertyHandle computedSet = table.getColumnBindings( );
> ComputedColumn cs1 = null;
>
> for( int i=0; i < cols.size(); i++){
> cs1 = StructureFactory.createComputedColumn();
> cs1.setName((String)cols.get(i));
> cs1.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]");
> computedSet.addItem(cs1);
> }
>
>
> // table header
> RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
>
>
> for( int i=0; i < cols.size(); i++){
> LabelHandle label1 = designFactory.newLabel( (String)cols.get(i) );
> label1.setText((String)cols.get(i));
> CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
> cell.getContent( ).add( label1 );
> }
>
> // table detail
> RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
> for( int i=0; i < cols.size(); i++){
> CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
> DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols.get(i) );
> data.setResultSetColumn( (String)cols.get(i));
> cell.getContent( ).add( data );
> }
>
> designHandle.getBody( ).add( table );
>
> // Save the design and close it.
>
> designHandle.saveAs( "c:/temp/sample.rptdesign" ); //$NON-NLS-1$
> designHandle.close( );
> System.out.println("Finished");
> }catch (Exception e){
> e.printStackTrace();
> }
>
> }
> }
Re: NullPointerException in buildDataSource [message #199033 is a reply to message #198964] Fri, 03 November 2006 19:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: home4slc.pacbell.net

Hi,

Jason helped me with this. Our BIRT_HOME is set fine, but what I did
not know (and the wiki entry does not mention it) is when you run the
application from Eclipse, all of the libraries under BIRT_HOME/lib must
be included in the Build Path for the project.

So in my environment, my BIRT_HOME was set to this:

C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine

so I added all of these jars to my Java Build Path in Eclipse;

chartengineapi.jar
com.ibm.icu_3.4.4.1.jar
commons-cli-1.0.jar
commons-codec-1.3.jar
coreapi.jar
dataadapterapi.jar
dteapi.jar
engineapi.jar
flute.jar
js.jar
modelapi.jar
org.eclipse.emf.common_2.2.0.v200606051102.jar
org.eclipse.emf.ecore.xmi_2.2.0.v200606051102.jar
org.eclipse.emf.ecore_2.2.0.v200606051102.jar
sac.jar
scriptapi.jar

I'll update the wiki page for this example to be more explicit about a)
setting BIRT_HOME for your machine, b) which reports have to exist
before hand and which one is created, and c) which jar files need to be
in the Eclipse Build Path.

Thanks,

Susan

M.c.P. wrote:
>
> Hi.
> I also twirled the first example (SimpleCreate.java) and I functioned
> correctly.
> Mine birt home is this: config.setProperty (“BIRT_HOME”, “C:
> /birtruntime/birt-runtime-2_1_1/ReportEngine”);
>
> It will be that it is problem in BIRT_HOME?
>
>
>
> Susan L. Cline escreveu:
>
>> Hi Jason,
>>
>> Regarding BIRT_HOME the first time I ran the example I figured out
>> this needed to be set, however, I am pointing only to the runtime.
>> Does it need to point to the full BIRT eclipse install?
>>
>> I will make comments to the wiki page after I get it running, because
>> I believe the instructions can be improved upon for others.
>>
>> Here is my BIRT_HOME:
>>
>> config.setProperty("BIRT_HOME",
>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine");
>>
>> C:\Documents and Settings\Administrator>dir
>> C:\projects\BIRT\downloads\birt-runt
>> ime-2_1_1\ReportEngine
>> Volume in drive C has no label.
>> Volume Serial Number is 8017-F8A8
>>
>> Directory of C:\projects\BIRT\downloads\birt-runtime-2_1_1\ReportEngine
>>
>> 10/31/2006 03:40 PM <DIR> .
>> 10/31/2006 03:40 PM <DIR> ..
>> 10/31/2006 03:40 PM <DIR> configuration
>> 09/26/2006 10:44 AM 1,485 genReport.bat
>> 09/26/2006 10:44 AM 1,105 genReport.sh
>> 10/16/2006 11:08 AM <DIR> lib
>> 10/16/2006 11:09 AM <DIR> plugins
>> 10/16/2006 11:08 AM <DIR> samples
>> 10/31/2006 11:45 AM <DIR> workspace
>> 2 File(s) 2,590 bytes
>> 7 Dir(s) 58,010,800,128 bytes free
>>
>> Which plugin do you suspect is not being found? If it is the plugin
>> containing ModelPlugin.class, I checked under the BIRT_HOME/plugins
>> directory and found the
>> org.eclipse.birt.report.model_2.1.1V20060926-0959.jar file which
>> contains this class.
>>
>> I've attached my java class for you to look at and see if you find
>> anything else if the setting I have for BIRT_HOME is correct.
>>
>> Also, I did run the SimpleCreate.java program and it ran successfully,
>> although I realize the second example is more complicated - but at
>> least my BIRT_HOME was set correctly for the first example.
>>
>> Regards,
>>
>> Susan
>>
>>
>> Jason Weathersby wrote:
>>
>>> What are you setting your BIRT HOME to?
>>>
>>> Jason
>>>
>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>> news:eia3tf$eca$1@utils.eclipse.org...
>>>
>>>> I already wrote this in bugzila:
>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>>>>
>>>> Thanks!
>>>>
>>>> Susan Cline escreveu:
>>>>
>>>>> Hi,
>>>>>
>>>>> I was trying to run this example as well and I am using the code
>>>>> that is on the wiki (the standard oda driver class, not Firebird.)
>>>>>
>>>>> I've been trying to debug this - I'm new to BIRT so I apologize
>>>>> ahead of time if some of the below is obvious to folks, but if
>>>>> someone could explain what is happening to help me learn, I'd be
>>>>> most appreciative.
>>>>>
>>>>> I'm getting a NullPointerException at this line in the
>>>>> DECreateDynamicTable.java code;
>>>>>
>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>> "Data Source",
>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>>
>>>>> It appears to me that in the newOdaDataSource method of
>>>>> org.eclipse.birt.report.model.api.ElementFactory.java
>>>>> that this line of code is returning null;
>>>>>
>>>>> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>>>>> extensionID ) == null )
>>>>>
>>>>> from there it appears that the instance of ODAProviderFactory is
>>>>> being creataed, but the NullPointerException is occuring when the
>>>>> createODAProvider method is being called.
>>>>>
>>>>> The createODAProvider method relies on the baseFactory variable, an
>>>>> IODAProviderFactory being initialized via the initeTheFactory
>>>>> method being called.
>>>>>
>>>>> The only place I can see where this method is called is in
>>>>> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try to
>>>>> debug the program it never appears to be called.
>>>>>
>>>>> So, if what I have said above is correct, what calls the
>>>>> ModelPlugin's start method, which is where the initeTheFactory
>>>>> method is called?
>>>>>
>>>>> Also, if this is a bug I'd be happy to log it in bugzilla, just let
>>>>> me know please.
>>>>>
>>>>> I'm using BIRT 2.1.1.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Susan
>>>>>
>>>>>
>>>>>
>>>>> Jason Weathersby wrote:
>>>>>
>>>>>> Does this driver exist in the drivers directory?
>>>>>> org.firebirdsql.jdbc.FBDriver
>>>>>>
>>>>>> Jason
>>>>>>
>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>> news:ei53gl$l3j$1@utils.eclipse.org...
>>>>>>
>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> I am trying to use to create the DataSource as in the example:
>>>>>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>>>>
>>>>>>> But this occurring the following error:
>>>>>>> java.lang.NullPointerException
>>>>>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>>>>
>>>>>>> This is the code that I am using:
>>>>>>> 164 public void buildDataSource() throws SemanticException {
>>>>>>> 165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>>>>>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>>>>> 167 dsHandle.setProperty("odaDriverClass",
>>>>>>> "org.firebirdsql.jdbc.FBDriver");
>>>>>>>
>>>>>>> ...
>>>>>>>
>>>>>>>
>>>>>>> Somebody could help me?
>>>>>>>
>>>>>>> Debtor for the attention.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>
>>>
>>
>>
>> ------------------------------------------------------------ ------------
>>
>> import java.io.IOException;
>> import java.util.ArrayList;
>> 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.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.OdaDataSetHandle;
>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>> 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.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.elements.structures.Comput edColumn;
>>
>> import com.ibm.icu.util.ULocale;
>>
>> /**
>> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
>> */
>>
>> public class DECreateDynamicTable
>> {
>> ReportDesignHandle designHandle = null;
>> ElementFactory designFactory = null;
>> StructureFactory structFactory = null;
>>
>> public static void main( String[] args )
>> {
>> try
>> {
>> DECreateDynamicTable de = new DECreateDynamicTable();
>> ArrayList al = new ArrayList();
>> al.add("OFFICECODE");
>> al.add("CITY");
>> al.add("COUNTRY");
>>
>> de.buildReport(al, "From Offices" );
>> }
>> catch ( IOException e )
>> {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> catch ( SemanticException e )
>> {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>>
>> void buildDataSource( ) throws SemanticException
>> {
>> OdaDataSourceHandle dsHandle = null;
>> System.out.println("designFactory is " +
>> designFactory.toString());
>> dsHandle = designFactory.newOdaDataSource(
>> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
>> System.out.println("dsHandle is " + dsHandle.toString());
>> dsHandle.setProperty( "odaDriverClass",
>> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
>> dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
>> dsHandle.setProperty( "odaUser", "ClassicModels" );
>> dsHandle.setProperty( "odaPassword", "" );
>>
>> designHandle.getDataSources( ).add( dsHandle );
>>
>> }
>>
>> void buildDataSet(ArrayList cols, String fromClause ) throws
>> SemanticException
>> {
>>
>> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
>>
>> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>> dsHandle.setDataSource( "Data Source" );
>> String qry = "Select ";
>> for( int i=0; i < cols.size(); i++){
>> qry += " " + cols.get(i);
>> if( i != (cols.size() -1) ){
>> qry += ",";
>> }
>>
>> }
>> qry += " " + fromClause;
>>
>> dsHandle.setQueryText( qry );
>>
>> designHandle.getDataSets( ).add( dsHandle );
>>
>>
>>
>> }
>> void buildReport(ArrayList cols, String fromClause ) throws
>> IOException, SemanticException
>> {
>>
>>
>> //Configure the Engine and start the Platform
>> DesignConfig config = new DesignConfig( );
>>
>> config.setProperty("BIRT_HOME",
>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/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();
>> }
>>
>>
>> try{
>> SessionHandle session = engine.newSessionHandle(
>> ULocale.ENGLISH ) ;
>> //open a design or a template
>> designHandle =
>> session.openDesign("c:/temp/hello_world.rptdesign");
>> designFactory = designHandle.getElementFactory( );
>> }
>> catch (Exception e){
>> e.printStackTrace();
>> System.exit(0);
>> }
>> try {
>> //designFactory = designHandle.getElementFactory( );
>>
>> buildDataSource();
>> buildDataSet(cols, fromClause);
>>
>> TableHandle table = designFactory.newTableItem( "table",
>> cols.size() );
>> table.setWidth( "100%" );
>> table.setDataSet( designHandle.findDataSet( "ds" ) );
>>
>> PropertyHandle computedSet =
>> table.getColumnBindings( ); ComputedColumn cs1 = null;
>>
>> for( int i=0; i < cols.size(); i++){
>> cs1 = StructureFactory.createComputedColumn();
>> cs1.setName((String)cols.get(i));
>> cs1.setExpression("dataSetRow[\"" +
>> (String)cols.get(i) + "\"]");
>> computedSet.addItem(cs1);
>> }
>>
>>
>> // table header
>> RowHandle tableheader = (RowHandle) table.getHeader(
>> ).get( 0 );
>>
>>
>> for( int i=0; i < cols.size(); i++){
>> LabelHandle label1 = designFactory.newLabel(
>> (String)cols.get(i) );
>> label1.setText((String)cols.get(i));
>> CellHandle cell = (CellHandle) tableheader.getCells(
>> ).get( i );
>> cell.getContent( ).add( label1 );
>> }
>>
>> // table detail
>> RowHandle tabledetail = (RowHandle) table.getDetail(
>> ).get( 0 );
>> for( int i=0; i < cols.size(); i++){
>> CellHandle cell = (CellHandle) tabledetail.getCells(
>> ).get( i );
>> DataItemHandle data = designFactory.newDataItem(
>> "data_"+(String)cols.get(i) );
>> data.setResultSetColumn( (String)cols.get(i));
>> cell.getContent( ).add( data );
>> }
>>
>> designHandle.getBody( ).add( table );
>>
>> // Save the design and close it.
>> designHandle.saveAs( "c:/temp/sample.rptdesign" );
>> //$NON-NLS-1$
>> designHandle.close( );
>> System.out.println("Finished");
>> }catch (Exception e){
>> e.printStackTrace();
>> }
>>
>> }
>> }
Re: NullPointerException in buildDataSource [message #199062 is a reply to message #199033] Fri, 03 November 2006 20:08 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Thanks Susan
"Susan Cline" <home4slc@pacbell.net> wrote in message
news:eig6js$38e$1@utils.eclipse.org...
> Hi,
>
> Jason helped me with this. Our BIRT_HOME is set fine, but what I did not
> know (and the wiki entry does not mention it) is when you run the
> application from Eclipse, all of the libraries under BIRT_HOME/lib must be
> included in the Build Path for the project.
>
> So in my environment, my BIRT_HOME was set to this:
>
> C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine
>
> so I added all of these jars to my Java Build Path in Eclipse;
>
> chartengineapi.jar
> com.ibm.icu_3.4.4.1.jar
> commons-cli-1.0.jar
> commons-codec-1.3.jar
> coreapi.jar
> dataadapterapi.jar
> dteapi.jar
> engineapi.jar
> flute.jar
> js.jar
> modelapi.jar
> org.eclipse.emf.common_2.2.0.v200606051102.jar
> org.eclipse.emf.ecore.xmi_2.2.0.v200606051102.jar
> org.eclipse.emf.ecore_2.2.0.v200606051102.jar
> sac.jar
> scriptapi.jar
>
> I'll update the wiki page for this example to be more explicit about a)
> setting BIRT_HOME for your machine, b) which reports have to exist before
> hand and which one is created, and c) which jar files need to be in the
> Eclipse Build Path.
>
> Thanks,
>
> Susan
>
> M.c.P. wrote:
>> Hi.
>> I also twirled the first example (SimpleCreate.java) and I functioned
>> correctly.
>> Mine birt home is this: config.setProperty (
Re: NullPointerException in buildDataSource [message #199388 is a reply to message #199062] Mon, 06 November 2006 19:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauricio.sag.com.br

Jason Weathersby escreveu:
> Thanks Susan
> "Susan Cline" <home4slc@pacbell.net> wrote in message
> news:eig6js$38e$1@utils.eclipse.org...
>> Hi,
>>
>> Jason helped me with this. Our BIRT_HOME is set fine, but what I did not
>> know (and the wiki entry does not mention it) is when you run the
>> application from Eclipse, all of the libraries under BIRT_HOME/lib must be
>> included in the Build Path for the project.
>>
>> So in my environment, my BIRT_HOME was set to this:
>>
>> C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine
>>
>> so I added all of these jars to my Java Build Path in Eclipse;
>>
>> chartengineapi.jar
>> com.ibm.icu_3.4.4.1.jar
>> commons-cli-1.0.jar
>> commons-codec-1.3.jar
>> coreapi.jar
>> dataadapterapi.jar
>> dteapi.jar
>> engineapi.jar
>> flute.jar
>> js.jar
>> modelapi.jar
>> org.eclipse.emf.common_2.2.0.v200606051102.jar
>> org.eclipse.emf.ecore.xmi_2.2.0.v200606051102.jar
>> org.eclipse.emf.ecore_2.2.0.v200606051102.jar
>> sac.jar
>> scriptapi.jar
>>
>> I'll update the wiki page for this example to be more explicit about a)
>> setting BIRT_HOME for your machine, b) which reports have to exist before
>> hand and which one is created, and c) which jar files need to be in the
>> Eclipse Build Path.
>>
>> Thanks,
>>
>> Susan
>>
>> M.c.P. wrote:
>>> Hi.
>>> I also twirled the first example (SimpleCreate.java) and I functioned
>>> correctly.
>>> Mine birt home is this: config.setProperty (“BIRT_HOME”, “C:
>>> /birtruntime/birt-runtime-2_1_1/ReportEngine”);
>>>
>>> It will be that it is problem in BIRT_HOME?
>>>
>>>
>>>
>>> Susan L. Cline escreveu:
>>>
>>>> Hi Jason,
>>>>
>>>> Regarding BIRT_HOME the first time I ran the example I figured out this
>>>> needed to be set, however, I am pointing only to the runtime. Does it
>>>> need to point to the full BIRT eclipse install?
>>>>
>>>> I will make comments to the wiki page after I get it running, because I
>>>> believe the instructions can be improved upon for others.
>>>>
>>>> Here is my BIRT_HOME:
>>>>
>>>> config.setProperty("BIRT_HOME",
>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine");
>>>>
>>>> C:\Documents and Settings\Administrator>dir
>>>> C:\projects\BIRT\downloads\birt-runt
>>>> ime-2_1_1\ReportEngine
>>>> Volume in drive C has no label.
>>>> Volume Serial Number is 8017-F8A8
>>>>
>>>> Directory of C:\projects\BIRT\downloads\birt-runtime-2_1_1\ReportEngine
>>>>
>>>> 10/31/2006 03:40 PM <DIR> .
>>>> 10/31/2006 03:40 PM <DIR> ..
>>>> 10/31/2006 03:40 PM <DIR> configuration
>>>> 09/26/2006 10:44 AM 1,485 genReport.bat
>>>> 09/26/2006 10:44 AM 1,105 genReport.sh
>>>> 10/16/2006 11:08 AM <DIR> lib
>>>> 10/16/2006 11:09 AM <DIR> plugins
>>>> 10/16/2006 11:08 AM <DIR> samples
>>>> 10/31/2006 11:45 AM <DIR> workspace
>>>> 2 File(s) 2,590 bytes
>>>> 7 Dir(s) 58,010,800,128 bytes free
>>>>
>>>> Which plugin do you suspect is not being found? If it is the plugin
>>>> containing ModelPlugin.class, I checked under the BIRT_HOME/plugins
>>>> directory and found the
>>>> org.eclipse.birt.report.model_2.1.1V20060926-0959.jar file which
>>>> contains this class.
>>>>
>>>> I've attached my java class for you to look at and see if you find
>>>> anything else if the setting I have for BIRT_HOME is correct.
>>>>
>>>> Also, I did run the SimpleCreate.java program and it ran successfully,
>>>> although I realize the second example is more complicated - but at least
>>>> my BIRT_HOME was set correctly for the first example.
>>>>
>>>> Regards,
>>>>
>>>> Susan
>>>>
>>>>
>>>> Jason Weathersby wrote:
>>>>
>>>>> What are you setting your BIRT HOME to?
>>>>>
>>>>> Jason
>>>>>
>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>> news:eia3tf$eca$1@utils.eclipse.org...
>>>>>
>>>>>> I already wrote this in bugzila:
>>>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> Susan Cline escreveu:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I was trying to run this example as well and I am using the code that
>>>>>>> is on the wiki (the standard oda driver class, not Firebird.)
>>>>>>>
>>>>>>> I've been trying to debug this - I'm new to BIRT so I apologize ahead
>>>>>>> of time if some of the below is obvious to folks, but if someone
>>>>>>> could explain what is happening to help me learn, I'd be most
>>>>>>> appreciative.
>>>>>>>
>>>>>>> I'm getting a NullPointerException at this line in the
>>>>>>> DECreateDynamicTable.java code;
>>>>>>>
>>>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>>>> "Data Source",
>>>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>>>>
>>>>>>> It appears to me that in the newOdaDataSource method of
>>>>>>> org.eclipse.birt.report.model.api.ElementFactory.java
>>>>>>> that this line of code is returning null;
>>>>>>>
>>>>>>> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>>>>>>> extensionID ) == null )
>>>>>>>
>>>>>>> from there it appears that the instance of ODAProviderFactory is
>>>>>>> being creataed, but the NullPointerException is occuring when the
>>>>>>> createODAProvider method is being called.
>>>>>>>
>>>>>>> The createODAProvider method relies on the baseFactory variable, an
>>>>>>> IODAProviderFactory being initialized via the initeTheFactory method
>>>>>>> being called.
>>>>>>>
>>>>>>> The only place I can see where this method is called is in
>>>>>>> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try to
>>>>>>> debug the program it never appears to be called.
>>>>>>>
>>>>>>> So, if what I have said above is correct, what calls the
>>>>>>> ModelPlugin's start method, which is where the initeTheFactory method
>>>>>>> is called?
>>>>>>>
>>>>>>> Also, if this is a bug I'd be happy to log it in bugzilla, just let
>>>>>>> me know please.
>>>>>>>
>>>>>>> I'm using BIRT 2.1.1.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Susan
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Jason Weathersby wrote:
>>>>>>>
>>>>>>>> Does this driver exist in the drivers directory?
>>>>>>>> org.firebirdsql.jdbc.FBDriver
>>>>>>>>
>>>>>>>> Jason
>>>>>>>>
>>>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>>>> news:ei53gl$l3j$1@utils.eclipse.org...
>>>>>>>>
>>>>>>>>
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> I am trying to use to create the DataSource as in the example:
>>>>>>>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>>>>>>
>>>>>>>>> But this occurring the following error:
>>>>>>>>> java.lang.NullPointerException
>>>>>>>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>>>>>>
>>>>>>>>> This is the code that I am using:
>>>>>>>>> 164 public void buildDataSource() throws SemanticException {
>>>>>>>>> 165 OdaDataSourceHandle dsHandle = reportFactory.newOdaDataSource(
>>>>>>>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>>>>>>> 167 dsHandle.setProperty("odaDriverClass",
>>>>>>>>> "org.firebirdsql.jdbc.FBDriver");
>>>>>>>>>
>>>>>>>>> ...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Somebody could help me?
>>>>>>>>>
>>>>>>>>> Debtor for the attention.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>
>>>>
>>>> ------------------------------------------------------------ ------------
>>>>
>>>> import java.io.IOException;
>>>> import java.util.ArrayList;
>>>> 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.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.OdaDataSetHandle;
>>>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>>>> 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.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.elements.structures.Comput edColumn;
>>>>
>>>> import com.ibm.icu.util.ULocale;
>>>>
>>>> /**
>>>> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
>>>> */
>>>>
>>>> public class DECreateDynamicTable
>>>> {
>>>> ReportDesignHandle designHandle = null;
>>>> ElementFactory designFactory = null;
>>>> StructureFactory structFactory = null; public static void main(
>>>> String[] args )
>>>> {
>>>> try
>>>> {
>>>> DECreateDynamicTable de = new DECreateDynamicTable();
>>>> ArrayList al = new ArrayList();
>>>> al.add("OFFICECODE");
>>>> al.add("CITY");
>>>> al.add("COUNTRY");
>>>> de.buildReport(al, "From Offices" );
>>>> }
>>>> catch ( IOException e )
>>>> {
>>>> // TODO Auto-generated catch block
>>>> e.printStackTrace();
>>>> }
>>>> catch ( SemanticException e )
>>>> {
>>>> // TODO Auto-generated catch block
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>>
>>>> void buildDataSource( ) throws SemanticException
>>>> {
>>>> OdaDataSourceHandle dsHandle = null;
>>>> System.out.println("designFactory is " +
>>>> designFactory.toString());
>>>> dsHandle = designFactory.newOdaDataSource(
>>>> "Data Source",
>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>> System.out.println("dsHandle is " + dsHandle.toString());
>>>> dsHandle.setProperty( "odaDriverClass",
>>>> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
>>>> dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
>>>> dsHandle.setProperty( "odaUser", "ClassicModels" );
>>>> dsHandle.setProperty( "odaPassword", "" );
>>>>
>>>> designHandle.getDataSources( ).add( dsHandle );
>>>>
>>>> }
>>>>
>>>> void buildDataSet(ArrayList cols, String fromClause ) throws
>>>> SemanticException
>>>> {
>>>>
>>>> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
>>>>
>>>> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>>>> dsHandle.setDataSource( "Data Source" );
>>>> String qry = "Select ";
>>>> for( int i=0; i < cols.size(); i++){
>>>> qry += " " + cols.get(i);
>>>> if( i != (cols.size() -1) ){
>>>> qry += ",";
>>>> }
>>>> }
>>>> qry += " " + fromClause;
>>>> dsHandle.setQueryText( qry );
>>>>
>>>> designHandle.getDataSets( ).add( dsHandle );
>>>> }
>>>> void buildReport(ArrayList cols, String fromClause ) throws
>>>> IOException, SemanticException
>>>> {
>>>>
>>>>
>>>> //Configure the Engine and start the Platform
>>>> DesignConfig config = new DesignConfig( );
>>>>
>>>> config.setProperty("BIRT_HOME",
>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/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();
>>>> }
>>>>
>>>> try{
>>>> SessionHandle session = engine.newSessionHandle(
>>>> ULocale.ENGLISH ) ;
>>>> //open a design or a template
>>>> designHandle =
>>>> session.openDesign("c:/temp/hello_world.rptdesign");
>>>> designFactory = designHandle.getElementFactory( );
>>>> }
>>>> catch (Exception e){
>>>> e.printStackTrace();
>>>> System.exit(0);
>>>> }
>>>> try {
>>>> //designFactory = designHandle.getElementFactory( );
>>>> buildDataSource();
>>>> buildDataSet(cols, fromClause);
>>>> TableHandle table = designFactory.newTableItem( "table", cols.size() );
>>>> table.setWidth( "100%" );
>>>> table.setDataSet( designHandle.findDataSet( "ds" ) );
>>>> PropertyHandle computedSet = table.getColumnBindings( );
>>>> ComputedColumn cs1 = null;
>>>>
>>>> for( int i=0; i < cols.size(); i++){
>>>> cs1 = StructureFactory.createComputedColumn();
>>>> cs1.setName((String)cols.get(i));
>>>> cs1.setExpression("dataSetRow[\"" + (String)cols.get(i)
>>>> + "\"]");
>>>> computedSet.addItem(cs1);
>>>> }
>>>> // table header
>>>> RowHandle tableheader = (RowHandle)
>>>> table.getHeader( ).get( 0 );
>>>>
>>>> for( int i=0; i < cols.size(); i++){
>>>> LabelHandle label1 = designFactory.newLabel(
>>>> (String)cols.get(i) ); label1.setText((String)cols.get(i));
>>>> CellHandle cell = (CellHandle)
>>>> tableheader.getCells( ).get( i );
>>>> cell.getContent( ).add( label1 );
>>>> } // table detail
>>>> RowHandle tabledetail = (RowHandle)
>>>> table.getDetail( ).get( 0 );
>>>> for( int i=0; i < cols.size(); i++){
>>>> CellHandle cell = (CellHandle)
>>>> tabledetail.getCells( ).get( i );
>>>> DataItemHandle data = designFactory.newDataItem(
>>>> "data_"+(String)cols.get(i) );
>>>> data.setResultSetColumn( (String)cols.get(i));
>>>> cell.getContent( ).add( data );
>>>> }
>>>> designHandle.getBody( ).add( table );
>>>> // Save the design and close it.
>>>> designHandle.saveAs( "c:/temp/sample.rptdesign" );
>>>> //$NON-NLS-1$
>>>> designHandle.close( );
>>>> System.out.println("Finished");
>>>> }catch (Exception e){
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>> }
>
>

Thanks for the aid, but, I tried to use the classroom of wiki and the
error continues the same, I mattered to.jar them that you it cited and I
conferred the BIRT_HOME, and exactly thus… continues the
NullPointerException.

It has something that I am making made a mistake?
It would have something more than I forgot to make?

Thanks

import java.io.IOException;
import java.util.ArrayList;

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.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.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
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.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.elements.structures.Comput edColumn;

import com.ibm.icu.util.ULocale;

/**
* Dynamic Table BIRT Design Engine API (DEAPI) demo.
*/

public class DECreateDynamicTable
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;

public void build( )
{
try
{
DECreateDynamicTable de = new DECreateDynamicTable();
ArrayList al = new ArrayList();
al.add("CODIPESS");
al.add("FANTPESS");
al.add("CODICIDA");

de.buildReport(al, "From POCAPESS" );
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

void buildDataSource( ) throws SemanticException
{

OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );

dsHandle.setProperty( "odaDriverClass",
"org.firebirdsql.jdbc.FBDriver" );

dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );

designHandle.getDataSources( ).add( dsHandle );

}

void buildDataSet(ArrayList cols, String fromClause ) throws
SemanticException
{

OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select ";
for( int i=0; i < cols.size(); i++){
qry += " " + cols.get(i);
if( i != (cols.size() -1) ){
qry += ",";
}

}
qry += " " + fromClause;

dsHandle.setQueryText( qry );

designHandle.getDataSets( ).add( dsHandle );



}
void buildReport(ArrayList cols, String fromClause ) throws
IOException, SemanticException
{


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

config.setProperty("BIRT_HOME",
"C:/birtruntime/birt-runtime-2_1_1/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 ) ;



try{
//open a design or a template
designHandle = session.openDesign("d:/temp/teste.rptdesign");

designFactory = designHandle.getElementFactory( );

buildDataSource();
buildDataSet(cols, fromClause);

TableHandle table = designFactory.newTableItem( "table", cols.size() );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ds" ) );


PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;

for( int i=0; i < cols.size(); i++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols.get(i));
cs1.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]");
computedSet.addItem(cs1);
}


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


for( int i=0; i < cols.size(); i++){
LabelHandle label1 = designFactory.newLabel( (String)cols.get(i) );
label1.setText((String)cols.get(i));
CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
cell.getContent( ).add( label1 );
}

// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for( int i=0; i < cols.size(); i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
DataItemHandle data = designFactory.newDataItem(
"data_"+(String)cols.get(i) );
data.setResultSetColumn( (String)cols.get(i));
cell.getContent( ).add( data );
}

designHandle.getBody( ).add( table );

// Save the design and close it.

designHandle.saveAs( "d:/temp/hoho.rptdesign" ); //$NON-NLS-1$
designHandle.close( );
System.out.println("Finished");
}catch (Exception e){
e.printStackTrace();
}

}
}
Re: NullPointerException in buildDataSource [message #199395 is a reply to message #199388] Mon, 06 November 2006 19:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: home4slc.pacbell.net

Hi,

I'm not sure I can help if it is an odaDriverClass problem (since you
are using firebird), but I would suggest running the example with the
standard odaDriverClass first just to see if you can get this working.

So change this line of your code:

dsHandle.setProperty( "odaDriverClass",
"org.firebirdsql.jdbc.FBDriver" );

to this:
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );

If this works, at least you know you have everything correct for the
standard driver and then you can try to troubleshoot the other problem.

Regards,

Susan

M.c.P. wrote:
> Jason Weathersby escreveu:
>
>> Thanks Susan
>> "Susan Cline" <home4slc@pacbell.net> wrote in message
>> news:eig6js$38e$1@utils.eclipse.org...
>>
>>> Hi,
>>>
>>> Jason helped me with this. Our BIRT_HOME is set fine, but what I did
>>> not know (and the wiki entry does not mention it) is when you run the
>>> application from Eclipse, all of the libraries under BIRT_HOME/lib
>>> must be included in the Build Path for the project.
>>>
>>> So in my environment, my BIRT_HOME was set to this:
>>>
>>> C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine
>>>
>>> so I added all of these jars to my Java Build Path in Eclipse;
>>>
>>> chartengineapi.jar
>>> com.ibm.icu_3.4.4.1.jar
>>> commons-cli-1.0.jar
>>> commons-codec-1.3.jar
>>> coreapi.jar
>>> dataadapterapi.jar
>>> dteapi.jar
>>> engineapi.jar
>>> flute.jar
>>> js.jar
>>> modelapi.jar
>>> org.eclipse.emf.common_2.2.0.v200606051102.jar
>>> org.eclipse.emf.ecore.xmi_2.2.0.v200606051102.jar
>>> org.eclipse.emf.ecore_2.2.0.v200606051102.jar
>>> sac.jar
>>> scriptapi.jar
>>>
>>> I'll update the wiki page for this example to be more explicit about
>>> a) setting BIRT_HOME for your machine, b) which reports have to exist
>>> before hand and which one is created, and c) which jar files need to
>>> be in the Eclipse Build Path.
>>>
>>> Thanks,
>>>
>>> Susan
>>>
>>> M.c.P. wrote:
>>>
>>>> Hi.
>>>> I also twirled the first example (SimpleCreate.java) and I
>>>> functioned correctly.
>>>> Mine birt home is this: config.setProperty (“BIRT_HOME”, “C:
>>>> /birtruntime/birt-runtime-2_1_1/ReportEngine”);
>>>>
>>>> It will be that it is problem in BIRT_HOME?
>>>>
>>>>
>>>>
>>>> Susan L. Cline escreveu:
>>>>
>>>>> Hi Jason,
>>>>>
>>>>> Regarding BIRT_HOME the first time I ran the example I figured out
>>>>> this needed to be set, however, I am pointing only to the runtime.
>>>>> Does it need to point to the full BIRT eclipse install?
>>>>>
>>>>> I will make comments to the wiki page after I get it running,
>>>>> because I believe the instructions can be improved upon for others.
>>>>>
>>>>> Here is my BIRT_HOME:
>>>>>
>>>>> config.setProperty("BIRT_HOME",
>>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine");
>>>>>
>>>>> C:\Documents and Settings\Administrator>dir
>>>>> C:\projects\BIRT\downloads\birt-runt
>>>>> ime-2_1_1\ReportEngine
>>>>> Volume in drive C has no label.
>>>>> Volume Serial Number is 8017-F8A8
>>>>>
>>>>> Directory of
>>>>> C:\projects\BIRT\downloads\birt-runtime-2_1_1\ReportEngine
>>>>>
>>>>> 10/31/2006 03:40 PM <DIR> .
>>>>> 10/31/2006 03:40 PM <DIR> ..
>>>>> 10/31/2006 03:40 PM <DIR> configuration
>>>>> 09/26/2006 10:44 AM 1,485 genReport.bat
>>>>> 09/26/2006 10:44 AM 1,105 genReport.sh
>>>>> 10/16/2006 11:08 AM <DIR> lib
>>>>> 10/16/2006 11:09 AM <DIR> plugins
>>>>> 10/16/2006 11:08 AM <DIR> samples
>>>>> 10/31/2006 11:45 AM <DIR> workspace
>>>>> 2 File(s) 2,590 bytes
>>>>> 7 Dir(s) 58,010,800,128 bytes free
>>>>>
>>>>> Which plugin do you suspect is not being found? If it is the
>>>>> plugin containing ModelPlugin.class, I checked under the
>>>>> BIRT_HOME/plugins directory and found the
>>>>> org.eclipse.birt.report.model_2.1.1V20060926-0959.jar file which
>>>>> contains this class.
>>>>>
>>>>> I've attached my java class for you to look at and see if you find
>>>>> anything else if the setting I have for BIRT_HOME is correct.
>>>>>
>>>>> Also, I did run the SimpleCreate.java program and it ran
>>>>> successfully, although I realize the second example is more
>>>>> complicated - but at least my BIRT_HOME was set correctly for the
>>>>> first example.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Susan
>>>>>
>>>>>
>>>>> Jason Weathersby wrote:
>>>>>
>>>>>> What are you setting your BIRT HOME to?
>>>>>>
>>>>>> Jason
>>>>>>
>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>> news:eia3tf$eca$1@utils.eclipse.org...
>>>>>>
>>>>>>> I already wrote this in bugzila:
>>>>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> Susan Cline escreveu:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I was trying to run this example as well and I am using the code
>>>>>>>> that is on the wiki (the standard oda driver class, not Firebird.)
>>>>>>>>
>>>>>>>> I've been trying to debug this - I'm new to BIRT so I apologize
>>>>>>>> ahead of time if some of the below is obvious to folks, but if
>>>>>>>> someone could explain what is happening to help me learn, I'd be
>>>>>>>> most appreciative.
>>>>>>>>
>>>>>>>> I'm getting a NullPointerException at this line in the
>>>>>>>> DECreateDynamicTable.java code;
>>>>>>>>
>>>>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>>>>> "Data Source",
>>>>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>>>>>
>>>>>>>> It appears to me that in the newOdaDataSource method of
>>>>>>>> org.eclipse.birt.report.model.api.ElementFactory.java
>>>>>>>> that this line of code is returning null;
>>>>>>>>
>>>>>>>> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>>>>>>>> extensionID ) == null )
>>>>>>>>
>>>>>>>> from there it appears that the instance of ODAProviderFactory is
>>>>>>>> being creataed, but the NullPointerException is occuring when
>>>>>>>> the createODAProvider method is being called.
>>>>>>>>
>>>>>>>> The createODAProvider method relies on the baseFactory variable,
>>>>>>>> an IODAProviderFactory being initialized via the initeTheFactory
>>>>>>>> method being called.
>>>>>>>>
>>>>>>>> The only place I can see where this method is called is in
>>>>>>>> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I try
>>>>>>>> to debug the program it never appears to be called.
>>>>>>>>
>>>>>>>> So, if what I have said above is correct, what calls the
>>>>>>>> ModelPlugin's start method, which is where the initeTheFactory
>>>>>>>> method is called?
>>>>>>>>
>>>>>>>> Also, if this is a bug I'd be happy to log it in bugzilla, just
>>>>>>>> let me know please.
>>>>>>>>
>>>>>>>> I'm using BIRT 2.1.1.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Susan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Jason Weathersby wrote:
>>>>>>>>
>>>>>>>>> Does this driver exist in the drivers directory?
>>>>>>>>> org.firebirdsql.jdbc.FBDriver
>>>>>>>>>
>>>>>>>>> Jason
>>>>>>>>>
>>>>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>>>>> news:ei53gl$l3j$1@utils.eclipse.org...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> Hi
>>>>>>>>>>
>>>>>>>>>> I am trying to use to create the DataSource as in the example:
>>>>>>>>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>>>>>>>
>>>>>>>>>> But this occurring the following error:
>>>>>>>>>> java.lang.NullPointerException
>>>>>>>>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>>>>>>>
>>>>>>>>>> This is the code that I am using:
>>>>>>>>>> 164 public void buildDataSource() throws SemanticException {
>>>>>>>>>> 165 OdaDataSourceHandle dsHandle =
>>>>>>>>>> reportFactory.newOdaDataSource(
>>>>>>>>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>>>>>>>> 167 dsHandle.setProperty("odaDriverClass",
>>>>>>>>>> "org.firebirdsql.jdbc.FBDriver");
>>>>>>>>>>
>>>>>>>>>> ...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Somebody could help me?
>>>>>>>>>>
>>>>>>>>>> Debtor for the attention.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>
>>>>>
>>>>> ------------------------------------------------------------ ------------
>>>>>
>>>>>
>>>>> import java.io.IOException;
>>>>> import java.util.ArrayList;
>>>>> 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.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.OdaDataSetHandle;
>>>>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>>>>> 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.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.elements.structures.Comput edColumn;
>>>>>
>>>>> import com.ibm.icu.util.ULocale;
>>>>>
>>>>> /**
>>>>> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
>>>>> */
>>>>>
>>>>> public class DECreateDynamicTable
>>>>> {
>>>>> ReportDesignHandle designHandle = null;
>>>>> ElementFactory designFactory = null;
>>>>> StructureFactory structFactory = null; public static void
>>>>> main( String[] args )
>>>>> {
>>>>> try
>>>>> {
>>>>> DECreateDynamicTable de = new DECreateDynamicTable();
>>>>> ArrayList al = new ArrayList();
>>>>> al.add("OFFICECODE");
>>>>> al.add("CITY");
>>>>> al.add("COUNTRY");
>>>>> de.buildReport(al, "From Offices" );
>>>>> }
>>>>> catch ( IOException e )
>>>>> {
>>>>> // TODO Auto-generated catch block
>>>>> e.printStackTrace();
>>>>> }
>>>>> catch ( SemanticException e )
>>>>> {
>>>>> // TODO Auto-generated catch block
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>>
>>>>> void buildDataSource( ) throws SemanticException
>>>>> {
>>>>> OdaDataSourceHandle dsHandle = null;
>>>>> System.out.println("designFactory is " +
>>>>> designFactory.toString());
>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>> "Data Source",
>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>> System.out.println("dsHandle is " + dsHandle.toString());
>>>>> dsHandle.setProperty( "odaDriverClass",
>>>>> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
>>>>> dsHandle.setProperty( "odaURL",
>>>>> "jdbc:classicmodels:sampledb" );
>>>>> dsHandle.setProperty( "odaUser", "ClassicModels" );
>>>>> dsHandle.setProperty( "odaPassword", "" );
>>>>>
>>>>> designHandle.getDataSources( ).add( dsHandle );
>>>>>
>>>>> }
>>>>>
>>>>> void buildDataSet(ArrayList cols, String fromClause ) throws
>>>>> SemanticException
>>>>> {
>>>>>
>>>>> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
>>>>>
>>>>> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>>>>> dsHandle.setDataSource( "Data Source" );
>>>>> String qry = "Select ";
>>>>> for( int i=0; i < cols.size(); i++){
>>>>> qry += " " + cols.get(i);
>>>>> if( i != (cols.size() -1) ){
>>>>> qry += ",";
>>>>> }
>>>>> }
>>>>> qry += " " + fromClause;
>>>>> dsHandle.setQueryText( qry );
>>>>>
>>>>> designHandle.getDataSets( ).add( dsHandle );
>>>>> }
>>>>> void buildReport(ArrayList cols, String fromClause ) throws
>>>>> IOException, SemanticException
>>>>> {
>>>>>
>>>>>
>>>>> //Configure the Engine and start the Platform
>>>>> DesignConfig config = new DesignConfig( );
>>>>>
>>>>> config.setProperty("BIRT_HOME",
>>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/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();
>>>>> }
>>>>>
>>>>> try{
>>>>> SessionHandle session = engine.newSessionHandle(
>>>>> ULocale.ENGLISH ) ;
>>>>> //open a design or a template
>>>>> designHandle =
>>>>> session.openDesign("c:/temp/hello_world.rptdesign");
>>>>> designFactory = designHandle.getElementFactory( );
>>>>> }
>>>>> catch (Exception e){
>>>>> e.printStackTrace();
>>>>> System.exit(0);
>>>>> }
>>>>> try {
>>>>> //designFactory = designHandle.getElementFactory( );
>>>>> buildDataSource();
>>>>> buildDataSet(cols, fromClause);
>>>>> TableHandle table = designFactory.newTableItem( "table",
>>>>> cols.size() );
>>>>> table.setWidth( "100%" );
>>>>> table.setDataSet( designHandle.findDataSet( "ds" ) );
>>>>> PropertyHandle computedSet = table.getColumnBindings( );
>>>>> ComputedColumn cs1 = null;
>>>>>
>>>>> for( int i=0; i < cols.size(); i++){
>>>>> cs1 = StructureFactory.createComputedColumn();
>>>>> cs1.setName((String)cols.get(i));
>>>>> cs1.setExpression("dataSetRow[\"" +
>>>>> (String)cols.get(i) + "\"]");
>>>>> computedSet.addItem(cs1);
>>>>> }
>>>>> // table header
>>>>> RowHandle tableheader = (RowHandle) table.getHeader(
>>>>> ).get( 0 );
>>>>>
>>>>> for( int i=0; i < cols.size(); i++){
>>>>> LabelHandle label1 = designFactory.newLabel(
>>>>> (String)cols.get(i) ); label1.setText((String)cols.get(i));
>>>>> CellHandle cell = (CellHandle)
>>>>> tableheader.getCells( ).get( i );
>>>>> cell.getContent( ).add( label1 );
>>>>> } // table detail
>>>>> RowHandle tabledetail = (RowHandle) table.getDetail(
>>>>> ).get( 0 );
>>>>> for( int i=0; i < cols.size(); i++){
>>>>> CellHandle cell = (CellHandle)
>>>>> tabledetail.getCells( ).get( i );
>>>>> DataItemHandle data = designFactory.newDataItem(
>>>>> "data_"+(String)cols.get(i) );
>>>>> data.setResultSetColumn( (String)cols.get(i));
>>>>> cell.getContent( ).add( data );
>>>>> }
>>>>> designHandle.getBody( ).add( table );
>>>>> // Save the design and close it.
>>>>> designHandle.saveAs( "c:/temp/sample.rptdesign" );
>>>>> //$NON-NLS-1$
>>>>> designHandle.close( );
>>>>> System.out.println("Finished");
>>>>> }catch (Exception e){
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>> }
>>
>>
>>
>
> Thanks for the aid, but, I tried to use the classroom of wiki and the
> error continues the same, I mattered to.jar them that you it cited and I
> conferred the BIRT_HOME, and exactly thus… continues the
> NullPointerException.
>
> It has something that I am making made a mistake?
> It would have something more than I forgot to make?
>
> Thanks
>
> import java.io.IOException;
> import java.util.ArrayList;
>
> 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.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.OdaDataSetHandle;
> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
> 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.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.elements.structures.Comput edColumn;
>
> import com.ibm.icu.util.ULocale;
>
> /**
> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
> */
>
> public class DECreateDynamicTable
> {
> ReportDesignHandle designHandle = null;
> ElementFactory designFactory = null;
> StructureFactory structFactory = null;
>
> public void build( )
> {
> try
> {
> DECreateDynamicTable de = new DECreateDynamicTable();
> ArrayList al = new ArrayList();
> al.add("CODIPESS");
> al.add("FANTPESS");
> al.add("CODICIDA");
>
> de.buildReport(al, "From POCAPESS" );
> }
> catch ( IOException e )
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch ( SemanticException e )
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> void buildDataSource( ) throws SemanticException
> {
>
> OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
>
> dsHandle.setProperty( "odaDriverClass",
> "org.firebirdsql.jdbc.FBDriver" );
>
> dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
> dsHandle.setProperty( "odaUser", "ClassicModels" );
> dsHandle.setProperty( "odaPassword", "" );
>
> designHandle.getDataSources( ).add( dsHandle );
>
> }
>
> void buildDataSet(ArrayList cols, String fromClause ) throws
> SemanticException
> {
>
> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
>
> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
> dsHandle.setDataSource( "Data Source" );
> String qry = "Select ";
> for( int i=0; i < cols.size(); i++){
> qry += " " + cols.get(i);
> if( i != (cols.size() -1) ){
> qry += ",";
> }
>
> }
> qry += " " + fromClause;
>
> dsHandle.setQueryText( qry );
>
> designHandle.getDataSets( ).add( dsHandle );
>
>
>
> }
> void buildReport(ArrayList cols, String fromClause ) throws
> IOException, SemanticException
> {
>
>
> //Configure the Engine and start the Platform
> DesignConfig config = new DesignConfig( );
>
> config.setProperty("BIRT_HOME",
> "C:/birtruntime/birt-runtime-2_1_1/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
> ) ;
>
>
>
> try{
> //open a design or a template
> designHandle = session.openDesign("d:/temp/teste.rptdesign");
>
> designFactory = designHandle.getElementFactory( );
>
> buildDataSource();
> buildDataSet(cols, fromClause);
>
> TableHandle table = designFactory.newTableItem( "table",
> cols.size() );
> table.setWidth( "100%" );
> table.setDataSet( designHandle.findDataSet( "ds" ) );
>
>
> PropertyHandle computedSet = table.getColumnBindings( );
> ComputedColumn cs1 = null;
>
> for( int i=0; i < cols.size(); i++){
> cs1 = StructureFactory.createComputedColumn();
> cs1.setName((String)cols.get(i));
> cs1.setExpression("dataSetRow[\"" + (String)cols.get(i)
> + "\"]");
> computedSet.addItem(cs1);
> }
>
>
> // table header
> RowHandle tableheader = (RowHandle) table.getHeader( ).get(
> 0 );
>
>
> for( int i=0; i < cols.size(); i++){
> LabelHandle label1 = designFactory.newLabel(
> (String)cols.get(i) );
> label1.setText((String)cols.get(i));
> CellHandle cell = (CellHandle) tableheader.getCells(
> ).get( i );
> cell.getContent( ).add( label1 );
> }
>
> // table detail
> RowHandle tabledetail = (RowHandle) table.getDetail( ).get(
> 0 );
> for( int i=0; i < cols.size(); i++){
> CellHandle cell = (CellHandle) tabledetail.getCells(
> ).get( i );
> DataItemHandle data = designFactory.newDataItem(
> "data_"+(String)cols.get(i) );
> data.setResultSetColumn( (String)cols.get(i));
> cell.getContent( ).add( data );
> }
>
> designHandle.getBody( ).add( table );
>
> // Save the design and close it.
>
> designHandle.saveAs( "d:/temp/hoho.rptdesign" ); //$NON-NLS-1$
> designHandle.close( );
> System.out.println("Finished");
> }catch (Exception e){
> e.printStackTrace();
> }
>
> }
> }
Re: NullPointerException in buildDataSource [message #199408 is a reply to message #199395] Mon, 06 November 2006 20:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauricio.sag.com.br

Hi.

You it could order its project to me?
so that I can use I eat example, since its functioned correctly.

Thanks

Susan Cline escreveu:
> Hi,
>
> I'm not sure I can help if it is an odaDriverClass problem (since you
> are using firebird), but I would suggest running the example with the
> standard odaDriverClass first just to see if you can get this working.
>
> So change this line of your code:
>
> dsHandle.setProperty( "odaDriverClass",
> "org.firebirdsql.jdbc.FBDriver" );
>
> to this:
> dsHandle.setProperty( "odaDriverClass",
> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
>
> If this works, at least you know you have everything correct for the
> standard driver and then you can try to troubleshoot the other problem.
>
> Regards,
>
> Susan
>
> M.c.P. wrote:
>> Jason Weathersby escreveu:
>>
>>> Thanks Susan
>>> "Susan Cline" <home4slc@pacbell.net> wrote in message
>>> news:eig6js$38e$1@utils.eclipse.org...
>>>
>>>> Hi,
>>>>
>>>> Jason helped me with this. Our BIRT_HOME is set fine, but what I
>>>> did not know (and the wiki entry does not mention it) is when you
>>>> run the application from Eclipse, all of the libraries under
>>>> BIRT_HOME/lib must be included in the Build Path for the project.
>>>>
>>>> So in my environment, my BIRT_HOME was set to this:
>>>>
>>>> C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine
>>>>
>>>> so I added all of these jars to my Java Build Path in Eclipse;
>>>>
>>>> chartengineapi.jar
>>>> com.ibm.icu_3.4.4.1.jar
>>>> commons-cli-1.0.jar
>>>> commons-codec-1.3.jar
>>>> coreapi.jar
>>>> dataadapterapi.jar
>>>> dteapi.jar
>>>> engineapi.jar
>>>> flute.jar
>>>> js.jar
>>>> modelapi.jar
>>>> org.eclipse.emf.common_2.2.0.v200606051102.jar
>>>> org.eclipse.emf.ecore.xmi_2.2.0.v200606051102.jar
>>>> org.eclipse.emf.ecore_2.2.0.v200606051102.jar
>>>> sac.jar
>>>> scriptapi.jar
>>>>
>>>> I'll update the wiki page for this example to be more explicit about
>>>> a) setting BIRT_HOME for your machine, b) which reports have to
>>>> exist before hand and which one is created, and c) which jar files
>>>> need to be in the Eclipse Build Path.
>>>>
>>>> Thanks,
>>>>
>>>> Susan
>>>>
>>>> M.c.P. wrote:
>>>>
>>>>> Hi.
>>>>> I also twirled the first example (SimpleCreate.java) and I
>>>>> functioned correctly.
>>>>> Mine birt home is this: config.setProperty (“BIRT_HOME”, “C:
>>>>> /birtruntime/birt-runtime-2_1_1/ReportEngine”);
>>>>>
>>>>> It will be that it is problem in BIRT_HOME?
>>>>>
>>>>>
>>>>>
>>>>> Susan L. Cline escreveu:
>>>>>
>>>>>> Hi Jason,
>>>>>>
>>>>>> Regarding BIRT_HOME the first time I ran the example I figured out
>>>>>> this needed to be set, however, I am pointing only to the
>>>>>> runtime. Does it need to point to the full BIRT eclipse install?
>>>>>>
>>>>>> I will make comments to the wiki page after I get it running,
>>>>>> because I believe the instructions can be improved upon for others.
>>>>>>
>>>>>> Here is my BIRT_HOME:
>>>>>>
>>>>>> config.setProperty("BIRT_HOME",
>>>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine");
>>>>>>
>>>>>> C:\Documents and Settings\Administrator>dir
>>>>>> C:\projects\BIRT\downloads\birt-runt
>>>>>> ime-2_1_1\ReportEngine
>>>>>> Volume in drive C has no label.
>>>>>> Volume Serial Number is 8017-F8A8
>>>>>>
>>>>>> Directory of
>>>>>> C:\projects\BIRT\downloads\birt-runtime-2_1_1\ReportEngine
>>>>>>
>>>>>> 10/31/2006 03:40 PM <DIR> .
>>>>>> 10/31/2006 03:40 PM <DIR> ..
>>>>>> 10/31/2006 03:40 PM <DIR> configuration
>>>>>> 09/26/2006 10:44 AM 1,485 genReport.bat
>>>>>> 09/26/2006 10:44 AM 1,105 genReport.sh
>>>>>> 10/16/2006 11:08 AM <DIR> lib
>>>>>> 10/16/2006 11:09 AM <DIR> plugins
>>>>>> 10/16/2006 11:08 AM <DIR> samples
>>>>>> 10/31/2006 11:45 AM <DIR> workspace
>>>>>> 2 File(s) 2,590 bytes
>>>>>> 7 Dir(s) 58,010,800,128 bytes free
>>>>>>
>>>>>> Which plugin do you suspect is not being found? If it is the
>>>>>> plugin containing ModelPlugin.class, I checked under the
>>>>>> BIRT_HOME/plugins directory and found the
>>>>>> org.eclipse.birt.report.model_2.1.1V20060926-0959.jar file which
>>>>>> contains this class.
>>>>>>
>>>>>> I've attached my java class for you to look at and see if you find
>>>>>> anything else if the setting I have for BIRT_HOME is correct.
>>>>>>
>>>>>> Also, I did run the SimpleCreate.java program and it ran
>>>>>> successfully, although I realize the second example is more
>>>>>> complicated - but at least my BIRT_HOME was set correctly for the
>>>>>> first example.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Susan
>>>>>>
>>>>>>
>>>>>> Jason Weathersby wrote:
>>>>>>
>>>>>>> What are you setting your BIRT HOME to?
>>>>>>>
>>>>>>> Jason
>>>>>>>
>>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>>> news:eia3tf$eca$1@utils.eclipse.org...
>>>>>>>
>>>>>>>> I already wrote this in bugzila:
>>>>>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>>>>>>>>
>>>>>>>> Thanks!
>>>>>>>>
>>>>>>>> Susan Cline escreveu:
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I was trying to run this example as well and I am using the
>>>>>>>>> code that is on the wiki (the standard oda driver class, not
>>>>>>>>> Firebird.)
>>>>>>>>>
>>>>>>>>> I've been trying to debug this - I'm new to BIRT so I apologize
>>>>>>>>> ahead of time if some of the below is obvious to folks, but if
>>>>>>>>> someone could explain what is happening to help me learn, I'd
>>>>>>>>> be most appreciative.
>>>>>>>>>
>>>>>>>>> I'm getting a NullPointerException at this line in the
>>>>>>>>> DECreateDynamicTable.java code;
>>>>>>>>>
>>>>>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>>>>>> "Data Source",
>>>>>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>>>>>>
>>>>>>>>> It appears to me that in the newOdaDataSource method of
>>>>>>>>> org.eclipse.birt.report.model.api.ElementFactory.java
>>>>>>>>> that this line of code is returning null;
>>>>>>>>>
>>>>>>>>> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>>>>>>>>> extensionID ) == null )
>>>>>>>>>
>>>>>>>>> from there it appears that the instance of ODAProviderFactory
>>>>>>>>> is being creataed, but the NullPointerException is occuring
>>>>>>>>> when the createODAProvider method is being called.
>>>>>>>>>
>>>>>>>>> The createODAProvider method relies on the baseFactory
>>>>>>>>> variable, an IODAProviderFactory being initialized via the
>>>>>>>>> initeTheFactory method being called.
>>>>>>>>>
>>>>>>>>> The only place I can see where this method is called is in
>>>>>>>>> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I
>>>>>>>>> try to debug the program it never appears to be called.
>>>>>>>>>
>>>>>>>>> So, if what I have said above is correct, what calls the
>>>>>>>>> ModelPlugin's start method, which is where the initeTheFactory
>>>>>>>>> method is called?
>>>>>>>>>
>>>>>>>>> Also, if this is a bug I'd be happy to log it in bugzilla, just
>>>>>>>>> let me know please.
>>>>>>>>>
>>>>>>>>> I'm using BIRT 2.1.1.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Susan
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Jason Weathersby wrote:
>>>>>>>>>
>>>>>>>>>> Does this driver exist in the drivers directory?
>>>>>>>>>> org.firebirdsql.jdbc.FBDriver
>>>>>>>>>>
>>>>>>>>>> Jason
>>>>>>>>>>
>>>>>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>>>>>> news:ei53gl$l3j$1@utils.eclipse.org...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> Hi
>>>>>>>>>>>
>>>>>>>>>>> I am trying to use to create the DataSource as in the example:
>>>>>>>>>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>>>>>>>>
>>>>>>>>>>> But this occurring the following error:
>>>>>>>>>>> java.lang.NullPointerException
>>>>>>>>>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>>>>>>>>
>>>>>>>>>>> This is the code that I am using:
>>>>>>>>>>> 164 public void buildDataSource() throws SemanticException {
>>>>>>>>>>> 165 OdaDataSourceHandle dsHandle =
>>>>>>>>>>> reportFactory.newOdaDataSource(
>>>>>>>>>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>>>>>>>>> 167 dsHandle.setProperty("odaDriverClass",
>>>>>>>>>>> "org.firebirdsql.jdbc.FBDriver");
>>>>>>>>>>>
>>>>>>>>>>> ...
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Somebody could help me?
>>>>>>>>>>>
>>>>>>>>>>> Debtor for the attention.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------ ------------
>>>>>>
>>>>>>
>>>>>> import java.io.IOException;
>>>>>> import java.util.ArrayList;
>>>>>> 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.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.OdaDataSetHandle;
>>>>>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>>>>>> 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.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.elements.structures.Comput edColumn;
>>>>>>
>>>>>> import com.ibm.icu.util.ULocale;
>>>>>>
>>>>>> /**
>>>>>> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
>>>>>> */
>>>>>>
>>>>>> public class DECreateDynamicTable
>>>>>> {
>>>>>> ReportDesignHandle designHandle = null;
>>>>>> ElementFactory designFactory = null;
>>>>>> StructureFactory structFactory = null; public static void
>>>>>> main( String[] args )
>>>>>> {
>>>>>> try
>>>>>> {
>>>>>> DECreateDynamicTable de = new DECreateDynamicTable();
>>>>>> ArrayList al = new ArrayList();
>>>>>> al.add("OFFICECODE");
>>>>>> al.add("CITY");
>>>>>> al.add("COUNTRY");
>>>>>> de.buildReport(al, "From Offices" );
>>>>>> }
>>>>>> catch ( IOException e )
>>>>>> {
>>>>>> // TODO Auto-generated catch block
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> catch ( SemanticException e )
>>>>>> {
>>>>>> // TODO Auto-generated catch block
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> void buildDataSource( ) throws SemanticException
>>>>>> {
>>>>>> OdaDataSourceHandle dsHandle = null;
>>>>>> System.out.println("designFactory is " +
>>>>>> designFactory.toString());
>>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>>> "Data Source",
>>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>>> System.out.println("dsHandle is " + dsHandle.toString());
>>>>>> dsHandle.setProperty( "odaDriverClass",
>>>>>> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
>>>>>> dsHandle.setProperty( "odaURL",
>>>>>> "jdbc:classicmodels:sampledb" );
>>>>>> dsHandle.setProperty( "odaUser", "ClassicModels" );
>>>>>> dsHandle.setProperty( "odaPassword", "" );
>>>>>>
>>>>>> designHandle.getDataSources( ).add( dsHandle );
>>>>>>
>>>>>> }
>>>>>>
>>>>>> void buildDataSet(ArrayList cols, String fromClause ) throws
>>>>>> SemanticException
>>>>>> {
>>>>>>
>>>>>> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet(
>>>>>> "ds",
>>>>>>
>>>>>> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>>>>>> dsHandle.setDataSource( "Data Source" );
>>>>>> String qry = "Select ";
>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>> qry += " " + cols.get(i);
>>>>>> if( i != (cols.size() -1) ){
>>>>>> qry += ",";
>>>>>> }
>>>>>> }
>>>>>> qry += " " + fromClause;
>>>>>> dsHandle.setQueryText( qry );
>>>>>>
>>>>>> designHandle.getDataSets( ).add( dsHandle );
>>>>>> }
>>>>>> void buildReport(ArrayList cols, String fromClause ) throws
>>>>>> IOException, SemanticException
>>>>>> {
>>>>>>
>>>>>>
>>>>>> //Configure the Engine and start the Platform
>>>>>> DesignConfig config = new DesignConfig( );
>>>>>>
>>>>>> config.setProperty("BIRT_HOME",
>>>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/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();
>>>>>> }
>>>>>>
>>>>>> try{
>>>>>> SessionHandle session = engine.newSessionHandle(
>>>>>> ULocale.ENGLISH ) ;
>>>>>> //open a design or a template
>>>>>> designHandle =
>>>>>> session.openDesign("c:/temp/hello_world.rptdesign");
>>>>>> designFactory = designHandle.getElementFactory( );
>>>>>> }
>>>>>> catch (Exception e){
>>>>>> e.printStackTrace();
>>>>>> System.exit(0);
>>>>>> }
>>>>>> try {
>>>>>> //designFactory = designHandle.getElementFactory( );
>>>>>> buildDataSource();
>>>>>> buildDataSet(cols, fromClause);
>>>>>> TableHandle table = designFactory.newTableItem( "table",
>>>>>> cols.size() );
>>>>>> table.setWidth( "100%" );
>>>>>> table.setDataSet( designHandle.findDataSet( "ds" ) );
>>>>>> PropertyHandle computedSet = table.getColumnBindings( );
>>>>>> ComputedColumn cs1 = null;
>>>>>>
>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>> cs1 = StructureFactory.createComputedColumn();
>>>>>> cs1.setName((String)cols.get(i));
>>>>>> cs1.setExpression("dataSetRow[\"" +
>>>>>> (String)cols.get(i) + "\"]");
>>>>>> computedSet.addItem(cs1);
>>>>>> }
>>>>>> // table header
>>>>>> RowHandle tableheader = (RowHandle) table.getHeader(
>>>>>> ).get( 0 );
>>>>>>
>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>> LabelHandle label1 = designFactory.newLabel(
>>>>>> (String)cols.get(i) ); label1.setText((String)cols.get(i));
>>>>>> CellHandle cell = (CellHandle)
>>>>>> tableheader.getCells( ).get( i );
>>>>>> cell.getContent( ).add( label1 );
>>>>>> } // table detail
>>>>>> RowHandle tabledetail = (RowHandle) table.getDetail(
>>>>>> ).get( 0 );
>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>> CellHandle cell = (CellHandle)
>>>>>> tabledetail.getCells( ).get( i );
>>>>>> DataItemHandle data = designFactory.newDataItem(
>>>>>> "data_"+(String)cols.get(i) );
>>>>>> data.setResultSetColumn( (String)cols.get(i));
>>>>>> cell.getContent( ).add( data );
>>>>>> }
>>>>>> designHandle.getBody( ).add( table );
>>>>>> // Save the design and close it.
>>>>>> designHandle.saveAs( "c:/temp/sample.rptdesign" );
>>>>>> //$NON-NLS-1$
>>>>>> designHandle.close( );
>>>>>> System.out.println("Finished");
>>>>>> }catch (Exception e){
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> }
>>>>>> }
>>>
>>>
>>>
>>
>> Thanks for the aid, but, I tried to use the classroom of wiki and the
>> error continues the same, I mattered to.jar them that you it cited and
>> I conferred the BIRT_HOME, and exactly thus… continues the
>> NullPointerException.
>>
>> It has something that I am making made a mistake?
>> It would have something more than I forgot to make?
>>
>> Thanks
>>
>> import java.io.IOException;
>> import java.util.ArrayList;
>>
>> 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.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.OdaDataSetHandle;
>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>> 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.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.elements.structures.Comput edColumn;
>>
>> import com.ibm.icu.util.ULocale;
>>
>> /**
>> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
>> */
>>
>> public class DECreateDynamicTable
>> {
>> ReportDesignHandle designHandle = null;
>> ElementFactory designFactory = null;
>> StructureFactory structFactory = null;
>> public void build( )
>> {
>> try
>> {
>> DECreateDynamicTable de = new DECreateDynamicTable();
>> ArrayList al = new ArrayList();
>> al.add("CODIPESS");
>> al.add("FANTPESS");
>> al.add("CODICIDA");
>> de.buildReport(al, "From POCAPESS" );
>> }
>> catch ( IOException e )
>> {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> catch ( SemanticException e )
>> {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>>
>> void buildDataSource( ) throws SemanticException
>> {
>>
>> OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
>> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
>> dsHandle.setProperty( "odaDriverClass",
>> "org.firebirdsql.jdbc.FBDriver" );
>> dsHandle.setProperty( "odaURL",
>> "jdbc:classicmodels:sampledb" );
>> dsHandle.setProperty( "odaUser", "ClassicModels" );
>> dsHandle.setProperty( "odaPassword", "" );
>>
>> designHandle.getDataSources( ).add( dsHandle );
>> }
>>
>> void buildDataSet(ArrayList cols, String fromClause ) throws
>> SemanticException
>> {
>>
>> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
>>
>> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>> dsHandle.setDataSource( "Data Source" );
>> String qry = "Select ";
>> for( int i=0; i < cols.size(); i++){
>> qry += " " + cols.get(i);
>> if( i != (cols.size() -1) ){
>> qry += ",";
>> }
>> }
>> qry += " " + fromClause;
>> dsHandle.setQueryText( qry );
>>
>> designHandle.getDataSets( ).add( dsHandle );
>> }
>> void buildReport(ArrayList cols, String fromClause ) throws
>> IOException, SemanticException
>> {
>>
>>
>> //Configure the Engine and start the Platform
>> DesignConfig config = new DesignConfig( );
>>
>> config.setProperty("BIRT_HOME",
>> "C:/birtruntime/birt-runtime-2_1_1/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 ) ;
>>
>>
>> try{
>> //open a design or a template
>> designHandle = session.openDesign("d:/temp/teste.rptdesign");
>>
>> designFactory = designHandle.getElementFactory( );
>>
>> buildDataSource();
>> buildDataSet(cols, fromClause);
>>
>> TableHandle table = designFactory.newTableItem( "table",
>> cols.size() );
>> table.setWidth( "100%" );
>> table.setDataSet( designHandle.findDataSet( "ds" ) );
>>
>> PropertyHandle computedSet =
>> table.getColumnBindings( );
>> ComputedColumn cs1 = null;
>>
>> for( int i=0; i < cols.size(); i++){
>> cs1 = StructureFactory.createComputedColumn();
>> cs1.setName((String)cols.get(i));
>> cs1.setExpression("dataSetRow[\"" +
>> (String)cols.get(i) + "\"]");
>> computedSet.addItem(cs1);
>> }
>> // table header
>> RowHandle tableheader = (RowHandle) table.getHeader(
>> ).get( 0 );
>>
>> for( int i=0; i < cols.size(); i++){
>> LabelHandle label1 = designFactory.newLabel(
>> (String)cols.get(i) );
>> label1.setText((String)cols.get(i));
>> CellHandle cell = (CellHandle) tableheader.getCells(
>> ).get( i );
>> cell.getContent( ).add( label1 );
>> } // table detail
>> RowHandle tabledetail = (RowHandle) table.getDetail(
>> ).get( 0 );
>> for( int i=0; i < cols.size(); i++){
>> CellHandle cell = (CellHandle) tabledetail.getCells(
>> ).get( i );
>> DataItemHandle data = designFactory.newDataItem(
>> "data_"+(String)cols.get(i) );
>> data.setResultSetColumn( (String)cols.get(i));
>> cell.getContent( ).add( data );
>> }
>>
>> designHandle.getBody( ).add( table );
>>
>> // Save the design and close it.
>>
>> designHandle.saveAs( "d:/temp/hoho.rptdesign" );
>> //$NON-NLS-1$
>> designHandle.close( );
>> System.out.println("Finished");
>> }catch (Exception e){
>> e.printStackTrace();
>> }
>> }
>> }
Re: NullPointerException in buildDataSource [message #199415 is a reply to message #199408] Mon, 06 November 2006 20:28 Go to previous message
Eclipse UserFriend
Originally posted by: mauricio.sag.com.br

Sorry my google english

M.c.P. escreveu:
> Hi.
>
> You it could order its project to me?
> so that I can use I eat example, since its functioned correctly.
>
> Thanks
>
> Susan Cline escreveu:
>> Hi,
>>
>> I'm not sure I can help if it is an odaDriverClass problem (since you
>> are using firebird), but I would suggest running the example with the
>> standard odaDriverClass first just to see if you can get this working.
>>
>> So change this line of your code:
>>
>> dsHandle.setProperty( "odaDriverClass",
>> "org.firebirdsql.jdbc.FBDriver" );
>>
>> to this:
>> dsHandle.setProperty( "odaDriverClass",
>> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
>>
>> If this works, at least you know you have everything correct for the
>> standard driver and then you can try to troubleshoot the other problem.
>>
>> Regards,
>>
>> Susan
>>
>> M.c.P. wrote:
>>> Jason Weathersby escreveu:
>>>
>>>> Thanks Susan
>>>> "Susan Cline" <home4slc@pacbell.net> wrote in message
>>>> news:eig6js$38e$1@utils.eclipse.org...
>>>>
>>>>> Hi,
>>>>>
>>>>> Jason helped me with this. Our BIRT_HOME is set fine, but what I
>>>>> did not know (and the wiki entry does not mention it) is when you
>>>>> run the application from Eclipse, all of the libraries under
>>>>> BIRT_HOME/lib must be included in the Build Path for the project.
>>>>>
>>>>> So in my environment, my BIRT_HOME was set to this:
>>>>>
>>>>> C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine
>>>>>
>>>>> so I added all of these jars to my Java Build Path in Eclipse;
>>>>>
>>>>> chartengineapi.jar
>>>>> com.ibm.icu_3.4.4.1.jar
>>>>> commons-cli-1.0.jar
>>>>> commons-codec-1.3.jar
>>>>> coreapi.jar
>>>>> dataadapterapi.jar
>>>>> dteapi.jar
>>>>> engineapi.jar
>>>>> flute.jar
>>>>> js.jar
>>>>> modelapi.jar
>>>>> org.eclipse.emf.common_2.2.0.v200606051102.jar
>>>>> org.eclipse.emf.ecore.xmi_2.2.0.v200606051102.jar
>>>>> org.eclipse.emf.ecore_2.2.0.v200606051102.jar
>>>>> sac.jar
>>>>> scriptapi.jar
>>>>>
>>>>> I'll update the wiki page for this example to be more explicit
>>>>> about a) setting BIRT_HOME for your machine, b) which reports have
>>>>> to exist before hand and which one is created, and c) which jar
>>>>> files need to be in the Eclipse Build Path.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Susan
>>>>>
>>>>> M.c.P. wrote:
>>>>>
>>>>>> Hi.
>>>>>> I also twirled the first example (SimpleCreate.java) and I
>>>>>> functioned correctly.
>>>>>> Mine birt home is this: config.setProperty (“BIRT_HOME”, “C:
>>>>>> /birtruntime/birt-runtime-2_1_1/ReportEngine”);
>>>>>>
>>>>>> It will be that it is problem in BIRT_HOME?
>>>>>>
>>>>>>
>>>>>>
>>>>>> Susan L. Cline escreveu:
>>>>>>
>>>>>>> Hi Jason,
>>>>>>>
>>>>>>> Regarding BIRT_HOME the first time I ran the example I figured
>>>>>>> out this needed to be set, however, I am pointing only to the
>>>>>>> runtime. Does it need to point to the full BIRT eclipse install?
>>>>>>>
>>>>>>> I will make comments to the wiki page after I get it running,
>>>>>>> because I believe the instructions can be improved upon for others.
>>>>>>>
>>>>>>> Here is my BIRT_HOME:
>>>>>>>
>>>>>>> config.setProperty("BIRT_HOME",
>>>>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/ReportEngine");
>>>>>>>
>>>>>>> C:\Documents and Settings\Administrator>dir
>>>>>>> C:\projects\BIRT\downloads\birt-runt
>>>>>>> ime-2_1_1\ReportEngine
>>>>>>> Volume in drive C has no label.
>>>>>>> Volume Serial Number is 8017-F8A8
>>>>>>>
>>>>>>> Directory of
>>>>>>> C:\projects\BIRT\downloads\birt-runtime-2_1_1\ReportEngine
>>>>>>>
>>>>>>> 10/31/2006 03:40 PM <DIR> .
>>>>>>> 10/31/2006 03:40 PM <DIR> ..
>>>>>>> 10/31/2006 03:40 PM <DIR> configuration
>>>>>>> 09/26/2006 10:44 AM 1,485 genReport.bat
>>>>>>> 09/26/2006 10:44 AM 1,105 genReport.sh
>>>>>>> 10/16/2006 11:08 AM <DIR> lib
>>>>>>> 10/16/2006 11:09 AM <DIR> plugins
>>>>>>> 10/16/2006 11:08 AM <DIR> samples
>>>>>>> 10/31/2006 11:45 AM <DIR> workspace
>>>>>>> 2 File(s) 2,590 bytes
>>>>>>> 7 Dir(s) 58,010,800,128 bytes free
>>>>>>>
>>>>>>> Which plugin do you suspect is not being found? If it is the
>>>>>>> plugin containing ModelPlugin.class, I checked under the
>>>>>>> BIRT_HOME/plugins directory and found the
>>>>>>> org.eclipse.birt.report.model_2.1.1V20060926-0959.jar file which
>>>>>>> contains this class.
>>>>>>>
>>>>>>> I've attached my java class for you to look at and see if you
>>>>>>> find anything else if the setting I have for BIRT_HOME is correct.
>>>>>>>
>>>>>>> Also, I did run the SimpleCreate.java program and it ran
>>>>>>> successfully, although I realize the second example is more
>>>>>>> complicated - but at least my BIRT_HOME was set correctly for the
>>>>>>> first example.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Susan
>>>>>>>
>>>>>>>
>>>>>>> Jason Weathersby wrote:
>>>>>>>
>>>>>>>> What are you setting your BIRT HOME to?
>>>>>>>>
>>>>>>>> Jason
>>>>>>>>
>>>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>>>> news:eia3tf$eca$1@utils.eclipse.org...
>>>>>>>>
>>>>>>>>> I already wrote this in bugzila:
>>>>>>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=162877
>>>>>>>>>
>>>>>>>>> Thanks!
>>>>>>>>>
>>>>>>>>> Susan Cline escreveu:
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I was trying to run this example as well and I am using the
>>>>>>>>>> code that is on the wiki (the standard oda driver class, not
>>>>>>>>>> Firebird.)
>>>>>>>>>>
>>>>>>>>>> I've been trying to debug this - I'm new to BIRT so I
>>>>>>>>>> apologize ahead of time if some of the below is obvious to
>>>>>>>>>> folks, but if someone could explain what is happening to help
>>>>>>>>>> me learn, I'd be most appreciative.
>>>>>>>>>>
>>>>>>>>>> I'm getting a NullPointerException at this line in the
>>>>>>>>>> DECreateDynamicTable.java code;
>>>>>>>>>>
>>>>>>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>>>>>>> "Data Source",
>>>>>>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>>>>>>>
>>>>>>>>>> It appears to me that in the newOdaDataSource method of
>>>>>>>>>> org.eclipse.birt.report.model.api.ElementFactory.java
>>>>>>>>>> that this line of code is returning null;
>>>>>>>>>>
>>>>>>>>>> if ( ODAProviderFactory.getInstance( ).createODAProvider( null,
>>>>>>>>>> extensionID ) == null )
>>>>>>>>>>
>>>>>>>>>> from there it appears that the instance of ODAProviderFactory
>>>>>>>>>> is being creataed, but the NullPointerException is occuring
>>>>>>>>>> when the createODAProvider method is being called.
>>>>>>>>>>
>>>>>>>>>> The createODAProvider method relies on the baseFactory
>>>>>>>>>> variable, an IODAProviderFactory being initialized via the
>>>>>>>>>> initeTheFactory method being called.
>>>>>>>>>>
>>>>>>>>>> The only place I can see where this method is called is in
>>>>>>>>>> org.eclipse.birt.report.model.plugin.ModelPlugin, and when I
>>>>>>>>>> try to debug the program it never appears to be called.
>>>>>>>>>>
>>>>>>>>>> So, if what I have said above is correct, what calls the
>>>>>>>>>> ModelPlugin's start method, which is where the initeTheFactory
>>>>>>>>>> method is called?
>>>>>>>>>>
>>>>>>>>>> Also, if this is a bug I'd be happy to log it in bugzilla,
>>>>>>>>>> just let me know please.
>>>>>>>>>>
>>>>>>>>>> I'm using BIRT 2.1.1.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Susan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Jason Weathersby wrote:
>>>>>>>>>>
>>>>>>>>>>> Does this driver exist in the drivers directory?
>>>>>>>>>>> org.firebirdsql.jdbc.FBDriver
>>>>>>>>>>>
>>>>>>>>>>> Jason
>>>>>>>>>>>
>>>>>>>>>>> "M.c.P." <mauricio@sag.com.br> wrote in message
>>>>>>>>>>> news:ei53gl$l3j$1@utils.eclipse.org...
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>> Hi
>>>>>>>>>>>>
>>>>>>>>>>>> I am trying to use to create the DataSource as in the example:
>>>>>>>>>>>> http://wiki.eclipse.org/index.php/Dynamic_Table
>>>>>>>>>>>>
>>>>>>>>>>>> But this occurring the following error:
>>>>>>>>>>>> java.lang.NullPointerException
>>>>>>>>>>>> at design.GeraArquivo.buildDataSource(GeraArquivo.java:167)
>>>>>>>>>>>>
>>>>>>>>>>>> This is the code that I am using:
>>>>>>>>>>>> 164 public void buildDataSource() throws SemanticException {
>>>>>>>>>>>> 165 OdaDataSourceHandle dsHandle =
>>>>>>>>>>>> reportFactory.newOdaDataSource(
>>>>>>>>>>>> 166 "Data Source", "org.eclipse.birt.report.data.oda.jdbc");
>>>>>>>>>>>> 167 dsHandle.setProperty("odaDriverClass",
>>>>>>>>>>>> "org.firebirdsql.jdbc.FBDriver");
>>>>>>>>>>>>
>>>>>>>>>>>> ...
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Somebody could help me?
>>>>>>>>>>>>
>>>>>>>>>>>> Debtor for the attention.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------ ------------
>>>>>>>
>>>>>>>
>>>>>>> import java.io.IOException;
>>>>>>> import java.util.ArrayList;
>>>>>>> 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.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.OdaDataSetHandle;
>>>>>>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>>>>>>> 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.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.elements.structures.Comput edColumn;
>>>>>>>
>>>>>>>
>>>>>>> import com.ibm.icu.util.ULocale;
>>>>>>>
>>>>>>> /**
>>>>>>> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
>>>>>>> */
>>>>>>>
>>>>>>> public class DECreateDynamicTable
>>>>>>> {
>>>>>>> ReportDesignHandle designHandle = null;
>>>>>>> ElementFactory designFactory = null;
>>>>>>> StructureFactory structFactory = null; public static void
>>>>>>> main( String[] args )
>>>>>>> {
>>>>>>> try
>>>>>>> {
>>>>>>> DECreateDynamicTable de = new DECreateDynamicTable();
>>>>>>> ArrayList al = new ArrayList();
>>>>>>> al.add("OFFICECODE");
>>>>>>> al.add("CITY");
>>>>>>> al.add("COUNTRY");
>>>>>>> de.buildReport(al, "From Offices" );
>>>>>>> }
>>>>>>> catch ( IOException e )
>>>>>>> {
>>>>>>> // TODO Auto-generated catch block
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> catch ( SemanticException e )
>>>>>>> {
>>>>>>> // TODO Auto-generated catch block
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> void buildDataSource( ) throws SemanticException
>>>>>>> {
>>>>>>> OdaDataSourceHandle dsHandle = null;
>>>>>>> System.out.println("designFactory is " +
>>>>>>> designFactory.toString());
>>>>>>> dsHandle = designFactory.newOdaDataSource(
>>>>>>> "Data Source",
>>>>>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>>>>>> System.out.println("dsHandle is " + dsHandle.toString());
>>>>>>> dsHandle.setProperty( "odaDriverClass",
>>>>>>>
>>>>>>> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
>>>>>>> dsHandle.setProperty( "odaURL",
>>>>>>> "jdbc:classicmodels:sampledb" );
>>>>>>> dsHandle.setProperty( "odaUser", "ClassicModels" );
>>>>>>> dsHandle.setProperty( "odaPassword", "" );
>>>>>>>
>>>>>>> designHandle.getDataSources( ).add( dsHandle );
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> void buildDataSet(ArrayList cols, String fromClause ) throws
>>>>>>> SemanticException
>>>>>>> {
>>>>>>>
>>>>>>> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet(
>>>>>>> "ds",
>>>>>>>
>>>>>>> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>>>>>>> dsHandle.setDataSource( "Data Source" );
>>>>>>> String qry = "Select ";
>>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>>> qry += " " + cols.get(i);
>>>>>>> if( i != (cols.size() -1) ){
>>>>>>> qry += ",";
>>>>>>> }
>>>>>>> }
>>>>>>> qry += " " + fromClause;
>>>>>>> dsHandle.setQueryText( qry );
>>>>>>>
>>>>>>> designHandle.getDataSets( ).add( dsHandle );
>>>>>>> }
>>>>>>> void buildReport(ArrayList cols, String fromClause ) throws
>>>>>>> IOException, SemanticException
>>>>>>> {
>>>>>>>
>>>>>>>
>>>>>>> //Configure the Engine and start the Platform
>>>>>>> DesignConfig config = new DesignConfig( );
>>>>>>>
>>>>>>> config.setProperty("BIRT_HOME",
>>>>>>> "C:/projects/BIRT/downloads/birt-runtime-2_1_1/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();
>>>>>>> }
>>>>>>>
>>>>>>> try{
>>>>>>> SessionHandle session = engine.newSessionHandle(
>>>>>>> ULocale.ENGLISH ) ;
>>>>>>> //open a design or a template
>>>>>>> designHandle =
>>>>>>> session.openDesign("c:/temp/hello_world.rptdesign");
>>>>>>> designFactory = designHandle.getElementFactory( );
>>>>>>> }
>>>>>>> catch (Exception e){
>>>>>>> e.printStackTrace();
>>>>>>> System.exit(0);
>>>>>>> }
>>>>>>> try {
>>>>>>> //designFactory = designHandle.getElementFactory( );
>>>>>>> buildDataSource();
>>>>>>> buildDataSet(cols, fromClause);
>>>>>>> TableHandle table = designFactory.newTableItem( "table",
>>>>>>> cols.size() );
>>>>>>> table.setWidth( "100%" );
>>>>>>> table.setDataSet( designHandle.findDataSet( "ds" ) );
>>>>>>> PropertyHandle computedSet = table.getColumnBindings( );
>>>>>>> ComputedColumn cs1 = null;
>>>>>>>
>>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>>> cs1 = StructureFactory.createComputedColumn();
>>>>>>> cs1.setName((String)cols.get(i));
>>>>>>> cs1.setExpression("dataSetRow[\"" +
>>>>>>> (String)cols.get(i) + "\"]");
>>>>>>> computedSet.addItem(cs1);
>>>>>>> }
>>>>>>> // table header
>>>>>>> RowHandle tableheader = (RowHandle) table.getHeader(
>>>>>>> ).get( 0 );
>>>>>>>
>>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>>> LabelHandle label1 = designFactory.newLabel(
>>>>>>> (String)cols.get(i) ); label1.setText((String)cols.get(i));
>>>>>>> CellHandle cell = (CellHandle)
>>>>>>> tableheader.getCells( ).get( i );
>>>>>>> cell.getContent( ).add( label1 );
>>>>>>> } // table detail
>>>>>>> RowHandle tabledetail = (RowHandle) table.getDetail(
>>>>>>> ).get( 0 );
>>>>>>> for( int i=0; i < cols.size(); i++){
>>>>>>> CellHandle cell = (CellHandle)
>>>>>>> tabledetail.getCells( ).get( i );
>>>>>>> DataItemHandle data =
>>>>>>> designFactory.newDataItem( "data_"+(String)cols.get(i) );
>>>>>>> data.setResultSetColumn( (String)cols.get(i));
>>>>>>> cell.getContent( ).add( data );
>>>>>>> }
>>>>>>> designHandle.getBody( ).add( table );
>>>>>>> // Save the design and close it.
>>>>>>> designHandle.saveAs( "c:/temp/sample.rptdesign" );
>>>>>>> //$NON-NLS-1$
>>>>>>> designHandle.close( );
>>>>>>> System.out.println("Finished");
>>>>>>> }catch (Exception e){
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> }
>>>>>>> }
>>>>
>>>>
>>>>
>>>
>>> Thanks for the aid, but, I tried to use the classroom of wiki and the
>>> error continues the same, I mattered to.jar them that you it cited
>>> and I conferred the BIRT_HOME, and exactly thus… continues the
>>> NullPointerException.
>>>
>>> It has something that I am making made a mistake?
>>> It would have something more than I forgot to make?
>>>
>>> Thanks
>>>
>>> import java.io.IOException;
>>> import java.util.ArrayList;
>>>
>>> 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.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.OdaDataSetHandle;
>>> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
>>> 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.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.elements.structures.Comput edColumn;
>>>
>>> import com.ibm.icu.util.ULocale;
>>>
>>> /**
>>> * Dynamic Table BIRT Design Engine API (DEAPI) demo.
>>> */
>>>
>>> public class DECreateDynamicTable
>>> {
>>> ReportDesignHandle designHandle = null;
>>> ElementFactory designFactory = null;
>>> StructureFactory structFactory = null; public void build( )
>>> {
>>> try
>>> {
>>> DECreateDynamicTable de = new DECreateDynamicTable();
>>> ArrayList al = new ArrayList();
>>> al.add("CODIPESS");
>>> al.add("FANTPESS");
>>> al.add("CODICIDA");
>>> de.buildReport(al, "From POCAPESS" );
>>> }
>>> catch ( IOException e )
>>> {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> catch ( SemanticException e )
>>> {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> void buildDataSource( ) throws SemanticException
>>> {
>>>
>>> OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
>>> "Data Source",
>>> "org.eclipse.birt.report.data.oda.jdbc" );
>>> dsHandle.setProperty( "odaDriverClass",
>>> "org.firebirdsql.jdbc.FBDriver" );
>>> dsHandle.setProperty( "odaURL",
>>> "jdbc:classicmodels:sampledb" );
>>> dsHandle.setProperty( "odaUser", "ClassicModels" );
>>> dsHandle.setProperty( "odaPassword", "" );
>>>
>>> designHandle.getDataSources( ).add( dsHandle );
>>> }
>>>
>>> void buildDataSet(ArrayList cols, String fromClause ) throws
>>> SemanticException
>>> {
>>>
>>> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
>>>
>>> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>>> dsHandle.setDataSource( "Data Source" );
>>> String qry = "Select ";
>>> for( int i=0; i < cols.size(); i++){
>>> qry += " " + cols.get(i);
>>> if( i != (cols.size() -1) ){
>>> qry += ",";
>>> }
>>> }
>>> qry += " " + fromClause;
>>> dsHandle.setQueryText( qry );
>>>
>>> designHandle.getDataSets( ).add( dsHandle );
>>> }
>>> void buildReport(ArrayList cols, String fromClause ) throws
>>> IOException, SemanticException
>>> {
>>>
>>>
>>> //Configure the Engine and start the Platform
>>> DesignConfig config = new DesignConfig( );
>>>
>>> config.setProperty("BIRT_HOME",
>>> "C:/birtruntime/birt-runtime-2_1_1/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 ) ;
>>>
>>> try{
>>> //open a design or a template
>>> designHandle =
>>> session.openDesign("d:/temp/teste.rptdesign");
>>>
>>> designFactory = designHandle.getElementFactory( );
>>>
>>> buildDataSource();
>>> buildDataSet(cols, fromClause);
>>>
>>> TableHandle table = designFactory.newTableItem( "table",
>>> cols.size() );
>>> table.setWidth( "100%" );
>>> table.setDataSet( designHandle.findDataSet( "ds" ) );
>>>
>>> PropertyHandle computedSet =
>>> table.getColumnBindings( );
>>> ComputedColumn cs1 = null;
>>>
>>> for( int i=0; i < cols.size(); i++){
>>> cs1 = StructureFactory.createComputedColumn();
>>> cs1.setName((String)cols.get(i));
>>> cs1.setExpression("dataSetRow[\"" +
>>> (String)cols.get(i) + "\"]");
>>> computedSet.addItem(cs1);
>>> }
>>> // table header
>>> RowHandle tableheader = (RowHandle) table.getHeader(
>>> ).get( 0 );
>>>
>>> for( int i=0; i < cols.size(); i++){
>>> LabelHandle label1 = designFactory.newLabel(
>>> (String)cols.get(i) );
>>> label1.setText((String)cols.get(i));
>>> CellHandle cell = (CellHandle) tableheader.getCells(
>>> ).get( i );
>>> cell.getContent( ).add( label1 );
>>> } // table detail
>>> RowHandle tabledetail = (RowHandle) table.getDetail(
>>> ).get( 0 );
>>> for( int i=0; i < cols.size(); i++){
>>> CellHandle cell = (CellHandle) tabledetail.getCells(
>>> ).get( i );
>>> DataItemHandle data = designFactory.newDataItem(
>>> "data_"+(String)cols.get(i) );
>>> data.setResultSetColumn( (String)cols.get(i));
>>> cell.getContent( ).add( data );
>>> }
>>>
>>> designHandle.getBody( ).add( table );
>>>
>>> // Save the design and close it.
>>>
>>> designHandle.saveAs( "d:/temp/hoho.rptdesign" );
>>> //$NON-NLS-1$
>>> designHandle.close( );
>>> System.out.println("Finished");
>>> }catch (Exception e){
>>> e.printStackTrace();
>>> } }
>>> }
Previous Topic:Using a different data set for header and detail
Next Topic:BIRT performance
Goto Forum:
  


Current Time: Wed Jul 17 14:39:36 GMT 2024

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

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

Back to the top