单独执行SWT显示crystalreport,并无BUG。可正常显示报表。但加在PLUGIN插件程序里时,显示
java.lang.NullPointerException
at com.crystaldecisions.Utilities.a.a(Unknown Source)
at com.crystaldecisions.Utilities.a.a(Unknown Source)
at com.crystaldecisions.Utilities.a.<init>(Unknown Source)
at com.crystaldecisions.Utilities.ImageButton.a(Unknown Source)
at com.crystaldecisions.Utilities.ImageButton.a(Unknown Source)
at com.crystaldecisions.Utilities.ImageButton.<init>(Unknown Source)
at com.businessobjects.crystalreports.viewer.applet.g.a(Unknown Source)
at com.crystaldecisions.ReportViewer.ReportViewer.start(Unknown Source)
at com.svw.vdm.composite.CrPrintCpt.initGUI(CrPrintCpt.java:111)
错误。。初步判断可能是crystalreport的JAR加载报表图片时,路径不对。
于是打印出SWT调用CRYSTALREPORT和PLUGIN调用CRYSTALREPORT的不同classLoader取水晶报表图片的路径,发现:
SWT显示的路径是::/D:/les_managedclient/com.xxx.yyy/bin/com/xxx/yyy/message.properties
而PLUGIN显示的是/com/svw/vdm/message.properties使用的classloader也不同:
SWT:class:sun.misc.Launcher$AppClassLoader
PLUGIN:org.eclipse.core.runtime.adaptor.EclipseClassLoader如果我想在PLUGIN中调用报表时使用AppClassLoader而非EclipseClassLoader,可能会解决问题。。
应该在程序中如何设定呢??
我不想在CLASSPATH中加载,因为会影响其他的模块。。3Q!!!!有其他好建议也可以提。

解决方案 »

  1.   

    补充部分源程序:
    public class CrPrintCpt extends org.eclipse.swt.widgets.Composite {
    private Composite composite1; private ReportClientDocument rpt; private ReportViewerBean viewer; private Frame frame1; /**
     * Auto-generated main method to display this
     * org.eclipse.swt.widgets.Composite inside a new Shell.
     */
    public static void main(String[] args) {
    // showGUI();
    // config.properties移出来// System.out.println(Utils.getSystemPath("report/Report2.rpt"));

    showGUI();
    } /**
     * Auto-generated method to display this org.eclipse.swt.widgets.Composite
     * inside a new Shell.
     */
    public static void showGUI() {
    Display display = Display.getDefault();
    Shell shell = new Shell(display);
    CrPrintCpt inst = new CrPrintCpt(shell, SWT.MAX);
    Point size = inst.getSize();
    shell.setLayout(new FillLayout());
    shell.layout();
    if (size.x == 0 && size.y == 0) {
    inst.pack();
    shell.pack();
    } else {
    Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
    shell.setSize(shellBounds.width, shellBounds.height);
    }
    shell.open();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    } public CrPrintCpt(org.eclipse.swt.widgets.Composite parent, int style) {
    super(parent, style);
    initGUI();
    } private void initGUI() {
    try {
    FillLayout thisLayout = new FillLayout(
    org.eclipse.swt.SWT.HORIZONTAL);
    this.setLayout(thisLayout);
    this.setSize(825, 381);
    this.addDisposeListener(new DisposeListener() {
    public void widgetDisposed(DisposeEvent evt) {
    System.out.println("this.widgetDisposed, event="+evt);
    //TODO add your code for this.widgetDisposed
    DbUtil.getInstance().closeAll();
    }
    });
    {
    composite1 = new Composite(this, SWT.EMBEDDED);
    FillLayout composite1Layout = new FillLayout();
    composite1.setLayout(composite1Layout);
    {
    frame1 = SWT_AWT.new_Frame(composite1);
    {
    createCR();
    frame1.add(viewer);
    // frame1.g
    // viewer.init();
    viewer.start();
    }
    }
    }
    this.layout();
    } catch (Exception e) {
    e.printStackTrace();
    }
    } /*
     * 创建一个crystal Recorder
     */
    private void createCR() throws ReportSDKException {
    // TODO Auto-generated method stub
    viewer = new ReportViewerBean();
    viewer.init(new String[0], null, null, null);
    rpt = new ReportClientDocument();

    ClassLoader cl = viewer.getClass().getClassLoader().getParent();
    ////
    // System.out.println("classLoader:"+cl.toString() );
    // System.out.println("URL="+cl.getResource("com/crystaldecisions/ReportViewer/ReportViewer16.gif").getPath());
    // System.out.println("URL="+cl.getResource("com/crystaldecisions/ReportViewer/ReportViewer16.gif").getFile());
    // System.out.println("URL="+cl.getResource("com/svw/vdm/message.properties").getFile()); rpt.open("c:/Report3.rpt", 0); IReportSource rptSource = rpt.getReportSource();
    viewer.setReportSource(rptSource);
    try {
    viewer.setHasGroupTree(false);// close left GroupMenu.
    viewer.setHasRefreshButton(false);
    viewer.addViewChangeListener(new ViewChangeAdapter() {
    public void viewClosed(ViewChangeEvent evt) {
    System.out.println("viewer.viewClosed, event=" + evt);
    // TODO add your code for viewer.viewClosed
    // DbUtil.getInstance().closeAll();
    }
    });
    } catch (PropertyVetoException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }