我想用文本字段显示一个简单的报告:" hello world"。
问题是我收到错误消息类别系列名称为空,我不知道原因。有人有线索吗?
服务器日志
net.sf.jasperreports.engine.JRRuntimeException: Category series name is null.
at net.sf.jasperreports.charts.fill.JRFillCategoryDataset.customIncrement(JRFillCategoryDataset.java:142)
at net.sf.jasperreports.engine.fill.JRFillElementDataset.increment(JRFillElementDataset.java:191)
at net.sf.jasperreports.engine.fill.JRCalculator.calculateVariables(JRCalculator.java:183)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:742)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:262)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:122)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:551)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:411)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:732)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:58)
at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:216)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
printreport方法:
public void printReport() throws JRException, IOException, NamingException, SQLException, ClassNotFoundException {
System.setProperty("java.awt.headless", "true");
File jasper = new File("/some/path/to/report.jasper");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasper.getPath(),new HashMap(), new JREmptyDataSource());
JasperExportManager.exportReportToPdfStream(jasperPrint, someOutputStream);
}
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="report name" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1119a425-bbc5-4d11-93a1-ab32daa4ccbc">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="254" y="22" width="100" height="20" uuid="a59aa154-093e-4330-8be7-515e56d76412"/>
<textFieldExpression><![CDATA["HELLO WORLD"]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
答案 0 :(得分:0)
问题是输入数据。
您正在使用以下方法:
fillReport(JasperReport jasperReport, java.util.Map<java.lang.String,java.lang.Object> parameters, JRDataSource dataSource)
但是,既没有参数也没有指定数据源。
JasperPrint jasperPrint = JasperFillManager.fillReport(jasper.getPath(),new HashMap(), new JREmptyDataSource());
我认为您的报告不仅包含标签。当您尝试在没有数据或类似结构的报表中显示图表时,会出现此错误。
答案 1 :(得分:0)
我有同样的问题,经过一小时比较代码,我发现值已经变为空白。试试这个
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="MYdataAdapter"/>