Java Jasper报告:无法将JRBeanCollectionDataSource解析为类型
我正在iReports中构建图表,当我在Eclipse中编译时,出现以下错误:Java Jasper报告:无法将JRBeanCollectionDataSource解析为类型,java,jasper-reports,ireport,Java,Jasper Reports,Ireport,我正在iReports中构建图表,当我在Eclipse中编译时,出现以下错误: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getValue())); //$JR_EXPR_ID=11$
<---------------------------------------------------->
2. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getOldValue())); //$JR_EXPR_ID=11$
<---------------------------------------------------->
3. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getValue())); //$JR_EXPR_ID=11$
<---------------------------------------------------->3 errors
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:204)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:240)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:173)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:448)
at org.reportprotojava.protosheet.Program.main(Program.java:122)
在我的图表数据源表达式中(并在我更改字段名称时更新),并且字段在iReport属性中设置为列表类型
这是我的.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ReportPrototype.jrxml" pageWidth="595" pageHeight="842" columnWidth="495" leftMargin="57" rightMargin="43" topMargin="43" bottomMargin="43" uuid="10825c57-f953-4166-bf03-8ecabe8a8f47">
<property name="ireport.zoom" value="0.75"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="232"/>
<subDataset name="ChartData" uuid="fc9ec0af-3e1a-40a7-8eb4-9ad30a266dee">
<field name="chartData.xAxis" class="java.lang.String"/>
</subDataset>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="title" class="java.lang.String"/>
<field name="logoLocation" class="java.lang.String"/>
<field name="picLocation" class="java.lang.String"/>
<field name="chartData.xAxis" class="java.lang.String"/>
<detail>
<band height="740" splitType="Stretch">
<textField isStretchWithOverflow="true" pattern="">
<reportElement uuid="519c6bb5-72f9-4c25-8e91-47865ae0c9df" mode="Opaque" x="39" y="75" width="378" height="45" forecolor="#000099"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
<font size="26"/>
</textElement>
<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<image onErrorType="Icon">
<reportElement uuid="3759a707-32a4-49ef-a9c6-b0ad7136f738" x="216" y="264" width="279" height="246"/>
<imageExpression><![CDATA[$F{picLocation}]]></imageExpression>
</image>
<image onErrorType="Icon">
<reportElement uuid="f989f871-32ea-4f13-ae3f-3f487cde76dd" x="295" y="0" width="200" height="42"/>
<imageExpression><![CDATA[$F{logoLocation}]]></imageExpression>
</image>
<xyLineChart>
<chart>
<reportElement uuid="ae87fc13-b92e-4a2a-b218-d395343f6028" x="0" y="537" width="495" height="203"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<dataset>
<datasetRun subDataset="ChartData" uuid="de7fb84d-17ea-4e5e-82bf-2015e72e4982">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})]]></dataSourceExpression>
</datasetRun>
</dataset>
</xyDataset>
<linePlot>
<plot/>
</linePlot>
</xyLineChart>
</band>
</detail>
<pageFooter>
<band height="16">
<break>
<reportElement uuid="0d30dea4-a6af-4e41-b7be-c288f3188dbf" x="0" y="11" width="100" height="1"/>
</break>
</band>
</pageFooter>
在我尝试过的iReports中:-创建和命名字段ProtoReport.ChartData.xAxis和ProtoReport.ChartData.yAxis下的字段和ChartData源添加的字段
-将字段重命名为ChartData.xAxis和ChartData.yAxis
-将字段重命名为chartData.xAxis和chartData.yAxis
-仅使用字段下的字段
-仅使用ChartData-fields下的字段 都给我一个错误。知道我做错了什么吗 其他问题:
-目前,我的图表可能只生成xAxis数据点。如何将一个阵列列表的内容用于X轴,另一个用于Y轴?即ChartData对象中的myxAxis和yAxis字段。
-我在main之前声明的randomData()方法在声明为static之前不会运行,这是为什么 编辑
更清楚地说明我的问题:如何命名字段、设置数据源和配置数据集以解决此问题?
我正在遵循评论中列出的教程(很抱歉没有超链接;作为一个新用户,我已经使用了所有超链接),并根据我的需要对其进行更改,但是他的数据结构比我的简单,我想学习如何在jasper reports中处理更复杂的对象和数据集。在.jrxml中,图表的数据源定义为:
<![CDATA[new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})]]>
但是这个表达式是错误的,因为缺少.data。应改为:
new net.sf.jasperreports.engine.data.JREmptyDataSource(1)
然后我将jreportydatasource(1)更改为JRBeanCollectionDataSource($F{chartData})
这修复了编译时错误,然后我不得不重新组织和定义我的列表和POJO,以便可以轻松访问ChartData对象的列表中的数据点对。从本质上说,这意味着我现在有了一个ChartData对象列表,每个对象只有一个XY点,而不是一个具有两个双精度列表(一个用于X轴,一个用于Y轴)的ChartData对象列表。这似乎目前效果不错。本教程非常有用
new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ReportPrototype.jrxml" pageWidth="595" pageHeight="842" columnWidth="495" leftMargin="57" rightMargin="43" topMargin="43" bottomMargin="43" uuid="10825c57-f953-4166-bf03-8ecabe8a8f47">
<property name="ireport.zoom" value="0.75"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="232"/>
<subDataset name="ChartData" uuid="fc9ec0af-3e1a-40a7-8eb4-9ad30a266dee">
<field name="chartData.xAxis" class="java.lang.String"/>
</subDataset>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="title" class="java.lang.String"/>
<field name="logoLocation" class="java.lang.String"/>
<field name="picLocation" class="java.lang.String"/>
<field name="chartData.xAxis" class="java.lang.String"/>
<detail>
<band height="740" splitType="Stretch">
<textField isStretchWithOverflow="true" pattern="">
<reportElement uuid="519c6bb5-72f9-4c25-8e91-47865ae0c9df" mode="Opaque" x="39" y="75" width="378" height="45" forecolor="#000099"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
<font size="26"/>
</textElement>
<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<image onErrorType="Icon">
<reportElement uuid="3759a707-32a4-49ef-a9c6-b0ad7136f738" x="216" y="264" width="279" height="246"/>
<imageExpression><![CDATA[$F{picLocation}]]></imageExpression>
</image>
<image onErrorType="Icon">
<reportElement uuid="f989f871-32ea-4f13-ae3f-3f487cde76dd" x="295" y="0" width="200" height="42"/>
<imageExpression><![CDATA[$F{logoLocation}]]></imageExpression>
</image>
<xyLineChart>
<chart>
<reportElement uuid="ae87fc13-b92e-4a2a-b218-d395343f6028" x="0" y="537" width="495" height="203"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<dataset>
<datasetRun subDataset="ChartData" uuid="de7fb84d-17ea-4e5e-82bf-2015e72e4982">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})]]></dataSourceExpression>
</datasetRun>
</dataset>
</xyDataset>
<linePlot>
<plot/>
</linePlot>
</xyLineChart>
</band>
</detail>
<pageFooter>
<band height="16">
<break>
<reportElement uuid="0d30dea4-a6af-4e41-b7be-c288f3188dbf" x="0" y="11" width="100" height="1"/>
</break>
</band>
</pageFooter>
<![CDATA[new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})]]>
new net.sf.jasperreports.engine.JREmptyDataSource(1)
new net.sf.jasperreports.engine.data.JREmptyDataSource(1)