SAP Knowledge Base Article - Public

1203279 - Null Pointer Exception in CRJ when using Command Object with Parameter for dynamic database connection

Symptom

  • A Crystal Report is designed using Command Object with parameter.
  • When attempting to change the datasource at runtime using ITable object of Crystal Reports for Java you are getting the following exception:

"Null Pointer Exception"

Environment

Occurs in Crystal Reports for Eclipse 1.0 and 2.0.

Cause

  • ITable sets the parameter for the command object after changing the table location.
  • Thus it contacting the destination datasource without any parameter and generates a "Null Pointer" exception.
     

Resolution

  • Use the IProcedure Object, which is included in the CRJ SDK.
  • It is used for both stored procedures and command objects, and has a method to get and set the parameter values before changing the datasource.
  • IProcedure object is documented in the RAS API documentation, which is available for the CRJ as well.
  • Below is a snippet that indicates how to use the iProcedure object on a command table in your report:
 
ITable table = tables.getTable(i);

if(table instanceof com.crystaldecisions.sdk.occa.report.data.CommandTable)
{
           IProcedure command = (IProcedure)table;
           ParameterField commandParam = (ParameterField) command.getParameters().get(0);
           Values values = new Values();
           ParameterFieldDiscreteValue pfdv = new ParameterFieldDiscreteValue();
           pfdv.setValue("ANTON");
           values.add(pfdv);
           commandParam.setCurrentValues(values);
}
 

Keywords

Null Pointer Exception after using Command Object with Parameter for dynamic database connection in the JRC thick client application , 6712056 , KBA , BI-DEV-JAV , BI Software Development Kits (SDKs) - Java , How To

Product

Crystal Reports, version for Eclipse 1.0 ; Crystal Reports, version for Eclipse 2.0