急救!在java中使用eclipse 的birt 插件的API运行报表总是报错?
原代码如下:
import java.util.HashMap;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.model.api.*;
import org.eclipse.birt.core.framework.*;
import org.junit.*;
public class TestB {
static void executeReport() throws EngineException
{
//Engine Configuration - set and get temp dir, BIRT home, Servlet context
EngineConfig config = new EngineConfig();
config.setEngineHome( "E:/birt/birt-runtime-2.1.2(1)/birt-runtime-2_1_2/ReportEngine " );
//Create the report engine
ReportEngine engine = new ReportEngine( config );
//Open a report design - use design to modify design, retrieve embedded images etc.
IReportRunnable design = engine.openReportDesign( "E:/workspace/My Report/Customers.rptdesign ");
//Create task to run the report - use the task to execute and run the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory( "image ");
HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );
task.setAppContext( contextMap );
//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName( "c:/customers.html ");
options.setOutputFormat( "html ");
task.setRenderOption(options);
//run the report and destroy the engine
task.run();
engine.destroy();
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
我把birt-runtime-2_1_2\ReportEngine\plugins文件夹下的所有包都导入了,还是报错,报错信息如下:
Mar 26, 2007 1:36:13 PM org.eclipse.birt.report.model.metadata.StructPropertyType validateValue
WARNING: The value of the structure is null
java.lang.NullPointerException
at org.eclipse.birt.report.model.elements.OdaDataSource.setIntrinsicProperty(OdaDataSource.java:201)
at org.eclipse.birt.report.model.core.DesignElement.setProperty(DesignElement.java:1192)
at org.eclipse.birt.report.model.core.DesignElement.setProperty(DesignElement.java:1162)
at org.eclipse.birt.report.model.parser.DesignParseState.setProperty(DesignParseState.java:99)
at org.eclipse.birt.report.model.parser.OdaDataSourceState.parseODADataSourceExtensionID(OdaDataSourceState.java:167)
at org.eclipse.birt.report.model.parser.OdaDataSourceState.parseAttrs(OdaDataSourceState.java:82)
at org.eclipse.birt.report.model.parser.ModuleParserHandler.startElement(ModuleParserHandler.java:145)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at org.eclipse.birt.report.model.parser.ModuleReader.readModule(ModuleReader.java:90)
at org.eclipse.birt.report.model.parser.DesignReader.read(DesignReader.java:90)
at org.eclipse.birt.report.model.core.DesignSession.openDesign(DesignSession.java:278)
at org.eclipse.birt.report.model.api.SessionHandle.openDesign(SessionHandle.java:291)
at org.eclipse.birt.report.engine.parser.ReportParser.getDesignHandle(ReportParser.java:160)
at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDesign(ReportEngineHelper.java:243)
at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDesign(ReportEngineHelper.java:191)
at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDesign(ReportEngineHelper.java:125)
at org.eclipse.birt.report.engine.api.impl.ReportEngine.openReportDesign(ReportEngine.java:225)
at org.eclipse.birt.report.engine.api.ReportEngine.openReportDesign(ReportEngine.java:112)
at TestB.executeReport(TestB.java:28)
at TestB.main(TestB.java:58)
求高手帮帮忙,小弟不胜感激!!
[解决办法]
你可以使用FineReport报表软件,操作简单、功能强大、服务贴心。即使你没用过报表软件,你也能在最短时间内做出一张完整的报表。
这个报表软件比较稳定,而且提供技术支持。
详情请登陆 http://www.finereport.com 查看。