Facing Null Pointer Exception while using BIRT

Posted by srikanth on Stack Overflow See other posts from Stack Overflow or by srikanth
Published on 2010-03-09T11:36:29Z Indexed on 2010/04/28 12:23 UTC
Read the original article Hit count: 1162

Filed under:
|
|

Hi, I am using BIRT APIs in a java program.My code is :

package com.tecnotree.mdx.product.utils;

import java.util.HashMap;
import java.util.logging.Level;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;


public class ExampleReport {

 public static void main(String[] args) {
  // Variables used to control BIRT Engine instance

  ReportEngine eng = null;
  IReportRunnable design = null;
  IRunAndRenderTask task = null;
  HTMLRenderOption renderContext = null;
  HashMap contextMap = null;
  HTMLRenderOption options = null;
  final EngineConfig conf = new EngineConfig();
  conf
    .setEngineHome("C:\\birt-runtime-2_5_2\\birt-runtime-2_5_2\\ReportEngine");
  System.out.println("conf " + conf.getBIRTHome());

  conf.setLogConfig(null, Level.FINE);
  try {
   Platform.startup(conf);
  } catch (BirtException e1) {
   // TODO Auto-generated catch block
   e1.printStackTrace();
  }


  IReportEngineFactory factory = (IReportEngineFactory) Platform
    .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
  System.out.println("Factory : " + factory.toString());
  System.out.println(conf.toString());
  IReportEngine engine = factory.createReportEngine(conf);
  System.out.println("Engine : " + engine);

  try {
   design = eng
     .openReportDesign("C:\\birt-runtime-2_5_2\\birt-runtime-2_5_2\\ReportEngine\\samples\\hello_world.rptdesign");
  } catch (Exception e) {
   System.err
     .println("An error occured during the opening of the report file!");
   e.printStackTrace();
   System.exit(-1);
  }
  task = eng.createRunAndRenderTask(design);
  renderContext = new HTMLRenderOption();
  renderContext.setImageDirectory("image");
  contextMap = new HashMap();
  contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
    renderContext);
  task.setAppContext(contextMap);

  options = new HTMLRenderOption();
  options.setOutputFileName("c:/temp/output.html");
  options.setOutputFormat("html");
  task.setRenderOption(options);
  try {
   task.run();
  } catch (Exception e) {
   System.err.println("An error occured while running the report!");
   e.printStackTrace();
   System.exit(-1);
  }
  System.out.println("All went well. Closing program!");
  eng.destroy();

 }
}

But i am facing NullPointerException while creating the report.

STACKTRACE :
Exception in thread "main" java.lang.NullPointerException
 at org.eclipse.birt.report.engine.api.impl.ReportEngine$EngineExtensionManager.<init>(ReportEngine.java:784)
 at org.eclipse.birt.report.engine.api.impl.ReportEngine.<init>(ReportEngine.java:109)
 at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:18)
 at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:1)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory.createReportEngine(ReportEngineFactory.java:14)
 at com.tecnotree.mdx.product.utils.ExampleReport.main(ExampleReport.java:47)

Please help me regarding this... my project deadline has been reached...

Appreciate your Reply

Thanks in Advance

© Stack Overflow or respective owner

Related posts about java

Related posts about birt