Java CrystalReports问题:无法创建临时文件:缺少参数值.----错误代码:-2147215357

时间:2017-05-20 05:09:09

标签: java crystal-reports crystal-reports-xi

可以帮助我解决此问题。我一直在尝试连接到BO服务器,在连接和设置参数后,尝试将其导出为pdf格式,这里我的代码无法说明缺少参数值。

下面用于获取ReportClientDocument的代码

IInfoObject infoObject = (IInfoObject) infoObjects.get(0);  

            IReportAppFactory reportAppFactory = (IReportAppFactory) enterpriseSession.getService("RASReportFactory");          
            //Open the report file          
            return reportAppFactory.openDocument(infoObject, OpenReportOptions._refreshRepositoryObjects , Locale.ENGLISH);

以下是用于设置参数的代码:

        ParameterFieldController paramFieldController = clientDoc.getDataDefController().getParameterFieldController();            
        Fields parameterFields = clientDoc.getDataDefinition().getParameterFields();
        for (int i = 0; i < parameterFields.size(); i++) {
            IParameterField paramToChange = (IParameterField) parameterFields.getField(i);
            String field = paramToChange.getName();             

            if (field.substring(0, 1).equalsIgnoreCase("@"))
                field = field.substring(1);
            else if (field.substring(0, 2).equalsIgnoreCase("V_"))
                field = field.substring(2);
            String value = null;
            System.out.println("Fields:  :i= "+i+ "  "+field);
            if (reportParam.get(field) != null)
                value = reportParam.get(field).toString();                
            else
                value = "";


            IParameterFieldDiscreteValue newDiscreteValue = new ParameterFieldDiscreteValue();
            System.out.println("Setting Parameter value :i= "+i+ "  "+value);
            newDiscreteValue.setValue(value);
            ParameterField tempParam = new ParameterField();
            paramToChange.copyTo(tempParam, false);
            if (tempParam.getCurrentValues().size() > 0)
                tempParam.getCurrentValues().remove(0);
            tempParam.getCurrentValues().add(0, newDiscreteValue);
            paramFieldController.modify(paramToChange, tempParam);

以下是我按顺序调用各种方法的顺序。

ReportClientDocument clientDoc = getDocumentFromInfoStore(enterpriseSession,crInfo.getReportsFolder(),reportName);

    if (!setDatabaseLocation(crInfo,clientDoc, sUserId, isILIReport)) {
        ReportLogger.debug("Error generating " + rptFileName + " report.<br/>" 
                + "Report Following Error Details<br/>"
                + "Database Location could not be set.");
        return null;
    } else if (!setReportParameters(clientDoc,reportParam)) {
        ReportLogger.debug("Error generating " + rptFileName + " report.<br/>"
                + "Report Following Error Details<br>"
                + "Database Parameters could not be set.");
        return null;
    } else if (!setFilter(reportParam, clientDoc)) {
        ReportLogger.debug("Error generating " + rptFileName + " report.<br/>"
                + "Report Following Error Details<br>"
                + "Database Filters could not be set.");
        return null;
    }else if (!setFooterCriteriaInfo(reportParam, clientDoc)) {
        ReportLogger.debug("Error generating " + rptFileName + " report.<br/>"
                + "Report Following Error Details<br>"
                + "Database Filters could not be set.");
        return null;
    }else if (!setSorting(reportParam, clientDoc)) {
        ReportLogger.debug("Error generating " + rptFileName + " report.<br/>"
                + "Report Following Error Details<br>"
                + "Database Filters could not be set.");
        return null;
    }

我做错了什么,你的帮助真的很明显! - 提前谢谢。

1 个答案:

答案 0 :(得分:0)

最后我解决了这个问题。解决方案如下

IParameterFieldDiscreteValue newDiscreteValue = new ParameterFieldDiscreteValue();
            System.out.println("Setting Parameter value :i= "+i+ "  "+value);
            newDiscreteValue.setValue(value);
            ParameterField tempParam = new ParameterField();
            **paramToChange.copyTo(tempParam, true);**

通过将copyTo方法boolean值更改为true,即,使PrameterField对象的深层副本解决了该问题。即 paramToChange.copyTo(tempParam,true);