【问题标题】:Getting exception while executing Jasper (Ireport) passing from JAVA [duplicate]执行从JAVA传递的Jasper(Ireport)时出现异常[重复]
【发布时间】:2021-01-12 19:09:52
【问题描述】:

抛出异常,无法从 bean 中识别字段名,

使用 Jaspersoft Studio 6.2.2 版创建的 JRXML 文件

    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="barcodeNo" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="28" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="11" width="85" height="17" uuid="dd489dd8-2c98-4aa0-9424-8f657197b22c"/>
                <jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="Code128" drawText="true" checksumRequired="false">
                    <jr:codeExpression><![CDATA[$F{barcodeNo}]]></jr:codeExpression>
                </jr:barbecue>
            </componentElement>
            <textField>
                <reportElement x="20" y="1" width="30" height="9" uuid="071ed7be-b4b9-4e60-8aea-0c9bb6cd55fe"/>
                <textElement>
                    <font size="4"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{barcodeNo}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

来自 java 服务

        List<String> barcodeList = getBarcodesFromRange(startBarcode, endBarcode);
        Map<String, Object> parametersMap = new HashMap<>();
        JasperReport jasperReport = JasperCompileManager.compileReport(resource.getInputStream());
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parametersMap, getDataSource());

        return jasperPrint;
    }


private static JRDataSource getDataSource() {
        Collection<BarcodePrint> coll = new ArrayList<>();
        coll.add(new BarcodePrint("1234","3333"));
        coll.add(new BarcodePrint("1111","3333"));

        return new JRBeanCollectionDataSource(coll);
    

填充数据的Bean

public class BarcodePrint{
String barcodeNo;
String desc;

    public BarcodePrint(String barcodeNo, String desc) {
        this.barcodeNo = barcodeNo;
        this.desc = desc;
    }

    public String getBarcodeNo() {
        return barcodeNo;
    }

    public void setBarcodeNo(String barcodeNo) {
        this.barcodeNo = barcodeNo;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}

获取异常,

原因:java.lang.NoSuchMethodException:类“com.int99.pos9.domain.BarcodePrint”上的未知属性“”

【问题讨论】:

    标签: java jasper-reports


    【解决方案1】:

    只需更改以下代码行,为我完成了技巧

    ` return new JRBeanCollectionDataSource(coll,false);`
    

    https://stackoverflow.com/a/41771599/3589086

    【讨论】:

    • 无需在 SO 上发布另一位作者已知解决方案的副本 - 最好将问题作为副本关闭(或直接删除)
    • 不同的问题/异常,但解决方法相同
    猜你喜欢
    • 1970-01-01
    • 2017-08-02
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 2012-05-21
    • 1970-01-01
    相关资源
    最近更新 更多