2010-03-09 71 views
2

我使用BIRT的API在Java代碼program.My面對NullPointerException異常是:同時使用BIRT

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(); 

} 
} 

但我在創建報告面臨NullPointerException異常。

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) 

請幫我對此...我的項目的最後期限已經達到...

感謝您的回覆提前

感謝

回答

1

不知道這是否會幫助,但你的違規行是:

IReportEngine engine = factory.createReportEngine(conf); 

我們不再編碼我們自己的web應用程序ns for BIRT(我們使用公司的另一部分提供的Web應用程序),但是通過我們的舊代碼進行挖掘,發現我們擁有的和您擁有的有所不同。無論他們中的一個是否修復,你都必須自己檢查。所有的護理,不承擔任何責任:-)

的區別是:

回家後設置日誌配置引擎,但在開始前的平臺,我們還建立了一個HTML發射器和平臺方面:

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); 

請記住,我們在一個servlet中運行,而不是作爲獨立應用程序的一部分。所以你可能需要:

IPlatformContext context = new PlatformFileContext(svrContext); 

爲平臺上下文。給一個鏡頭,看看它是否有效。不知何故,我懷疑它,因爲PlatformFileContext是默認的。發射器可能是需要考慮的事情。

我可以建議的唯一的其他可能性是實際得到source code for BIRT (your particular build)並查看堆棧跟蹤中的違規行。你應該希望能夠找出哪個參數可能導致問題。

例如,最後一行ReportEngine.java:784是部分:

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

所以它幾乎可以肯定,在通過document爲null。你需要通過各個層面來回顧一下,試圖找出發生的事情。

這可能很難在這種情況下,您可能會更好,只需raising a bug report並讓專家處理它。或麻煩傑森Weathersby直接,如果你能得到你骯髒的小手放在他的電子郵件地址:-)


順便說一句,你不需要那些可怕的在你的路逃跑\字符。 Java是在處理(例如)完美的罰款:

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

我遇到了類似的問題,離開了它讀Report Engine API documentation page

一些基本的東西是:

  • 發生在你的項目ReportEngine文件夾,你可以發現裏面BIRT運行時下載:那就是你需要處理.rptdesign文件,並得到該報告中的所有引擎作爲輸出
  • 添加到Java構建路徑中的所有jar文件ReportEngine/lib目錄
  • 添加與司機必要的罐子連接到您的DBS在ReportEngine /插件/ org.eclipse.birt.report.data.oda.jdbc_xxx (不需要將它們添加到Java構建路徑)

示例代碼生成一個HTML報告:

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.*; 

/**This class reads an .rptdesign file, 
* and gives as output a report in HTML format 
*/ 
public class BirtEngineDesktop { 

    public static void main(String[] args) { 
     // Variables used to control BIRT Engine instance 
     String reportName = "first_report.rptdesign"; 
     IReportEngine engine = null; 
     IReportRunnable design = null; 
     IRunAndRenderTask task = null; 
     HTMLRenderOption renderContext = null; 
     HashMap contextMap = null; 
     HTMLRenderOption options = null; 
     final EngineConfig conf = new EngineConfig(); 
     conf.setEngineHome("ReportEngine"); 
     System.out.println("BIRT_HOME: " + conf.getBIRTHome()); 
     conf.setLogConfig(null, Level.FINE); 

     try { 
      Platform.startup(conf); 
     } catch (BirtException e1) { 
      e1.printStackTrace(); 
     } 

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

     try { 
      design = engine.openReportDesign("report/" + reportName); //report is needed in this folder 
     } catch (Exception e) { 
      System.err.println("An error occured during the opening of the report file!"); 
      e.printStackTrace(); 
      System.exit(-1); 
     } 
     task = engine.createRunAndRenderTask(design); 
     renderContext = new HTMLRenderOption(); 
     renderContext.setImageDirectory("images"); 
     contextMap = new HashMap(); 
     contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, 
       renderContext); 
     task.setAppContext(contextMap); 

     //Set parameter values and validate, if the report requires it 
     //task.setParameterValue("Years", 2.0); 
     //task.validateParameters(); 

     options = new HTMLRenderOption(); 
     options.setOutputFileName("output/" + reportName + ".html"); //output HTML will go to this folder 
     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!"); 
     engine.destroy(); 
     System.exit(0); 
    } 
} 
0

我知道這個問題是很老,但我今天就遇到了這個問題,我花了很長時間才弄明白什麼原因是。原因是我在我的類路徑中包含了一些birt/eclipse依賴項。無論出於何種原因,這會導致這個奇怪的錯誤我正在使用maven幷包含一些自定義發射器。我的解決方案是將我的eclipse相關性標記爲「自定義發射器」中的「提供」。這使得所有的eclipse cruft不會進入類路徑,而是依靠BIRT的OSGI加載來處理所有這些。

0

我也面臨這個問題

IReportEngine engine = factory.createReportEngine(conf); 
//was null everytime. 

我所做的一切,「藍色」中描述,但仍然存在的錯誤。 我通過下載並重新安裝ReportEngine從here.

解決了這個問題在我的情況下,我的插件中沒有配置文件夾。將配置文件夾添加到我的插件後,一切都很好。