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

Java CrystalReports issue : Can not create temp file: Missing parameter values.---- Error code:-2147215357

任何人都可以帮助我解决这个问题。我一直在尝试连接到 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;
    }

我是不是做错了什么,你的帮助真的很可观!! -提前致谢。

我终于解决了这个问题。解决方法如下

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 方法的布尔值更改为 true,即制作 PrameterField 对象的深层副本解决了该问题。即 paramToChange.copyTo(tempParam, true);