views:

584

answers:

1

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

A: 

Not sure if this will help but your offending line is:

IReportEngine engine = factory.createReportEngine(conf);

We no longer code our own web applications for BIRT (we use a web application provided by another part of the company) but digging through our old code found two differences between what we had and what you have. Whether one of them is a fix, you'll have to check for yourself. All care, no responsibility :-)

The differences are:

After setting the log config engine home but before starting the platform, we also set up an HTML emitter and the platform context:

HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig();
emitterConfig.setActionHandler (new HTMLActionHandler());
HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
emitterConfig.setImageHandler (imageHandler);
conf.getEmitterConfigs().put ("html", emitterConfig);

IPlatformContext context = new PlatformServletContext( svrContext );
conf.setPlatformContext( context );

Keep in mind we were running in a servlet, not as part of a standalone application. So you'll probably need:

IPlatformContext context = new PlatformFileContext( svrContext );

for the platform context. Give that a shot and see if it works. Somehow I doubt it since PlatformFileContext is the default. The emitter might be something to consider though.

The only other possibility I can suggest is to actually get the source code for BIRT (your particular build) and have a look at the offending lines in the stack trace. You should hopefully be able to figure out which parameter may be causing the problem.

For example, the final line ReportEngine.java:784 is part of:

void cacheOpenedDocument( ReportDocumentReader document ) {
    synchronized ( openedDocuments ) {
        LinkedEntry<ReportDocumentReader> entry
            = openedDocuments.add( document );
        document.setEngineCacheEntry( entry ); // << line 784
    }
}

so it's almost certainly that the document passed in was null. You'll need to follow that back through the various layers to try and find out what's happening.

This may well be difficult in which case you may be better off just raising a bug report and letting the experts handle it. Or hassle Jason Weathersby directly if you can get your grubby little hands on his email address :-)


As an aside, you don't need those hideous escaped \ characters in your paths. Java is perfectly fine in dealing with (for example):

conf.setEngineHome("C:/birt-runtime-2_5_2/ReportEngine");
paxdiablo