Отчет и вложенный отчет SDK Java Crystal Report - параметр Subreport дает ошибку Код ошибки: -2147217394 Имя кода ошибки: missingParameterValueError - PullRequest
0 голосов
/ 20 июня 2019

Я интегрирую Crystal Report с Java и смог экспортировать отчет в PDF, когда у меня есть отчет без вложенных отчетов.

Тем не менее, я получаю сообщение об ошибке, когда я включаю подотчет с одним параметром, хотя я объявляю значение параметра в подотчете.

Параметр подотчета:

reportClientDocument.getDataDefController().getParameterFieldController().setCurrentValue("TranslateLabels", "Pm-@PrintLanguage", new String("ENG"));

Я не уверен, чего не хватает, или мне нужно предоставить значение другим способом.

Пожалуйста, позвольте мнезнаете, чего не хватает?или если вы можете приложить пример, он будет очень признателен.

Ошибка:

The program is giving error: Error code:-2147217394 Error code name:missingParameterValueError

Caused by: com.crystaldecisions.reports.common.MissingParameterValuesException: Some parameters are missing values

Полный код:

public static void printInvoice(int invoiceNum) throws Exception{
    Connection c = null;
    PreparedStatement ps;
    PreparedStatement pssub;
    ResultSet rs = null;
    ResultSet rssub = null;
    String subreportName = "TranslateLabels";
    String mainReportParamName = "PrintLanguage";
    String mainReportParamValue = "ENG";

    try {
        c = DBConnectionPools.getConn();
        StringBuffer sb = new StringBuffer();
        sb.append(" SELECT * FROM Invoice inv ");
        sb.append(" LEFT JOIN Language  la ON inv.PrintLang = la.PrintLang ");
        sb.append(" WHERE InvoiceNum = ?  ");
        ps = c.prepareStatement(sb.toString());
        ps.setInt(1, invoiceNum);
        rs = ps.executeQuery();

        //Main Report 
        ReportClientDocument reportClientDocument = new ReportClientDocument();
        reportClientDocument.open("H:Invoice.rpt",0);
        reportClientDocument.getDatabaseController().setDataSource(rs);
        reportClientDocument.getDataDefController().getParameterFieldController().setCurrentValue("", mainReportParamName, mainReportParamValue);

        //Sub Report
        pssub = c.prepareStatement("SELECT * from Language WHERE PrintLang = 'ENG' ");
        rssub = pssub.executeQuery();
        reportClientDocument.getSubreportController().setDataSource(subreportName, rssub);
        reportClientDocument.getDataDefController().getParameterFieldController().setCurrentValue(subreportName, "Pm-@PrintLanguage", "ENG");

        InputStream in = (InputStream) reportClientDocument.getPrintOutputController().export(ReportExportFormat.PDF);
        OutputStream out = new FileOutputStream("C:invoice.pdf");
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
           out.write(buf, 0, len);
        }
        in.close();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if(null != c) {
            c.close();
        }
    }
}

Я получаю следующую ошибку:

Caused by: com.crystaldecisions.reports.common.MissingParameterValuesException: Some parameters are missing values
    at com.crystaldecisions.reports.dataengine.DataSourceManagerCoordinator.a(SourceFile:592)
    at com.crystaldecisions.reports.dataengine.DataSourceManager.if(SourceFile:1085)
    at com.crystaldecisions.reports.dataengine.DataSourceManager.a(SourceFile:1099)
    at com.crystaldecisions.reports.dataengine.DataProcessor2.a(SourceFile:734)
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.ObjectFormatter.<init>(SourceFile:179)
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.ObjectFormatter.if(SourceFile:135)
    at com.crystaldecisions.reports.formatter.formatter.paginator.PageFormatterBase.<init>(SourceFile:75)
    at com.crystaldecisions.reports.formatter.formatter.paginator.PageFormatter.<init>(SourceFile:183)
    at com.crystaldecisions.reports.formatter.formatter.paginator.PageFormatter.a(SourceFile:162)
    at com.crystaldecisions.reports.formatter.export2.a.a(SourceFile:202)
    ... 27 more
ERROR common - Failed to load the resource 'InternalFormatterException' from the bundle java.util.PropertyResourceBundle@4837635d.
java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key InternalFormatterException
    at java.util.ResourceBundle.getObject(Unknown Source)
    at java.util.ResourceBundle.getString(Unknown Source)
    at com.crystaldecisions.reports.common.CrystalResources.loadString(Unknown Source)
    at com.crystaldecisions.reports.common.CrystalResources.loadMessage(Unknown Source)
    at com.crystaldecisions.reports.common.CrystalResourcesFactory.getLocalizedMessage(Unknown Source)
    at com.crystaldecisions.reports.common.CrystalException.getLocalizedMessage(Unknown Source)
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.a(SourceFile:2257)
INFO  JRCLicenseThrottler -  releasing engine request
DEBUG commandmanager - command SETUP: NotUndoableCommand
DEBUG commandmanager - command PERFORM: NotUndoableCommand
DEBUG commandmanager - -- command is NOT UNDOABLE -> purge undo stack
com.crystaldecisions.sdk.occa.report.lib.ReportSDKParameterFieldException: InternalFormatterException---- Error code:-2147217394 Error code name:missingParameterValueError
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.if(SourceFile:237)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(SourceFile:147)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(SourceFile:128)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(SourceFile:111)
    at com.company.project.client.ui.controls.Test.printInvoice(Test.java:466)
    at com.company.project.client.ui.controls.Test.main(Test.java:400)
...