Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
null pointer exception while starting the engine
vineethakp
This is my code for combining two reports.
=============================================================================================================
package com.report.test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
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.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.PDFRenderOption;
public class Combine {
public void runReport() throws BirtException, IOException
{
IReportEngine iReportEngine =null;
EngineConfig engineConfig = null;
try
{
engineConfig = new EngineConfig();
engineConfig.setEngineHome("C:\\birt-runtime-2_6_2\\birt-runtime-2_6_2\\ReportEngine");
System.out.println("Setting Engine Home");
engineConfig.setLogConfig(null, Level.OFF);
Platform.startup(engineConfig);
System.out.println("Platform Started");
IReportEngineFactory iReportEngineFactory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
iReportEngine = iReportEngineFactory.createReportEngine(engineConfig);
System.out.println("Report Engine Created");
}
catch (Exception e) {
e.printStackTrace();
}
IReportRunnable design1 = iReportEngine.openReportDesign("F:\\MyWorkSpace\\Merging\\WebRoot\\reports\\Report_A.rptdesign");
IReportRunnable design2 = iReportEngine.openReportDesign("F:\\MyWorkSpace\\Merging\\WebRoot\\reports\\Report_B.rptdesign");
IRunAndRenderTask iRunAndRenderTask = iReportEngine.createRunAndRenderTask(design1);
FileOutputStream fileOutputStream1 = new FileOutputStream("C/output/combined.pdf", true);
PDFRenderOption pdfRenderOption = new PDFRenderOption();
pdfRenderOption.setOutputStream(fileOutputStream1);
pdfRenderOption.setOutputFormat("PDF");
iRunAndRenderTask.setRenderOption(pdfRenderOption);
iRunAndRenderTask.run();
iRunAndRenderTask = iReportEngine.createRunAndRenderTask(design2);
FileOutputStream fileOutputStream2 = new FileOutputStream("C/output/combined.pdf", true);
pdfRenderOption.setOutputStream(fileOutputStream2);
iRunAndRenderTask.setRenderOption(pdfRenderOption);
iRunAndRenderTask.run();
fileOutputStream1.flush();
fileOutputStream2.flush();
fileOutputStream1.close();
fileOutputStream2.close();
iRunAndRenderTask.close();
iReportEngine.destroy();
Platform.shutdown();
System.out.println("Finished");
}
public static void main(String args[]) throws FileNotFoundException, BirtException
{
try {
Combine combine = new Combine();
combine.runReport();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
=============================================================================================================
But i am getting this Exception.
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.report.test.Combine.runReport(Combine.java:33)
at com.report.test.Combine.main(Combine.java:74)
java.lang.NullPointerException
at com.report.test.Combine.runReport(Combine.java:40)
at com.report.test.Combine.main(Combine.java:74)
If my code is perfect. Please tell me in detail what jars should be copied to my workspace lib from birt-runtime.
Find more posts tagged with
Comments
JasonW
Try something like the following:
package REAPI;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
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 java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfCopyFields;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
public class CombineReportsPDF {
public void concat(byte[] ba1, byte[] ba2, String outpath){
try{
//Document document = new Document();
//ByteArrayOutputStream baos = new ByteArrayOutputStream();
//PdfWriter writer = PdfWriter.getInstance(document, baos);
//PdfAction pdfAction = new PdfAction(PdfAction.PRINTDIALOG);
//writer.setOpenAction(pdfAction);
//document.open();
//writer.addJavaScript(
// "this.print({bUI: true,bSilent: false,bShrinkToFit: true});" +
//"\r\n" +
//"this.closeDoc();"
//);
//document.add(new Paragraph("What is this doing"));
//PdfReader js1 = new PdfReader(baos.toByteArray());
PdfReader rd1 = new PdfReader( ba1 );
PdfReader rd2 = new PdfReader( ba2 );
PdfCopyFields cpy = new PdfCopyFields( new FileOutputStream( outpath ));
//cpy.addDocument(js1);
cpy.addDocument(rd1);
cpy.addDocument(rd2);
//cpy.addJavaScript( "this.print({bUI: true,bSilent: false,bShrinkToFit: true});" +
// "\r\n" +
// "this.closeDoc();"
// );
//document.close();
cpy.close();
}catch(Exception e){
e.printStackTrace();
}
}
public void runReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");
config.setLogConfig(null, Level.OFF);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}
IReportRunnable design, design2 = null;
//Open the report design
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
design2 = engine.openReportDesign("Reports/TopSellingProducts.rptdesign");
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("Top Percentage", (new Integer(3)));
task.setParameterValue("Top Count", (new Integer(5)));
task.validateParameters();
PDFRenderOption options = new PDFRenderOption();
ByteArrayOutputStream fso= new ByteArrayOutputStream();
ByteArrayOutputStream fso2= new ByteArrayOutputStream();
options.setOutputStream(fso);
options.setOutputFormat("pdf");
task.setRenderOption(options);
task.run();
task.close();
//Create task to run and render the report,
task = engine.createRunAndRenderTask(design2);
options.setOutputStream(fso2);
options.setOutputFormat("pdf");
task.setRenderOption(options);
task.run();
task.close();
concat( fso.toByteArray(), fso2.toByteArray(), "output/resample/Combined.pdf");
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
CombineReportsPDF ex = new CombineReportsPDF( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Put the jars in the report engine download birt-runtime-version\ReportEngine\lib
in your buildpath if you are using eclipse. Also add com.lowagie.text_version.jar from the plugins directory
birt-runtime-version\ReportEngine\plugins to your build path.
Jason
vineethakp
Hi Jason,
Null pointer exception is gone and the new error has started. The error is
Exception in thread "main" java.lang.NoSuchMethodError: org.eclipse.birt.report.engine.api.EngineConfig.getLogRollingSize()I
at org.eclipse.birt.report.engine.api.impl.ReportEngine.intializeLogger(ReportEngine.java:217)
at org.eclipse.birt.report.engine.api.impl.ReportEngine.<init>(ReportEngine.java:133)
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.report.test.CombineReportsPDF.runReport(CombineReportsPDF.java:77)
at com.report.test.CombineReportsPDF.main(CombineReportsPDF.java:135)
Please have a look. Thanks for the reply and Please reply as soon as possible. I am hanging on this from a week.
-Vineeth
JasonW
Did you add all the jars from the report engine lib? This looks like a classpath issue. Also did you change your birt home to where you have it?
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");
Jason
vineethakp
Hi Jason.
I set the Birt Home path correctly.
I have copied all the jar files from Birt Runtime lib directory to my project lib directory.
Is there anything else to copy? Please let me know.
Thank you,
Vineeth
JasonW
You did not need to copy the libs just reference them in the build path. Is this an eclipse application?
If so download the applications here and import them to your workspace and update the build path to point to the right location.
Jason
JasonW
sorry forgot the link:
http://www.birt-exchange.org/org/devshare/deploying-birt-reports/1187-eclipsecon-2010-birt-metal-ppt/