问题
在Jasperreport中,如果表详细信息单元格或标题单元格的内容很大而无法容纳在一页中,则会引发运行时 NullPointer异常。在Jasperreports Studio和Jasperreports Server中都可以观察到此行为。
版本
6.6和6.7
JRXML
为简单起见,使用空数据集。这里重要的是文本 字段需要将其溢出时的延伸属性设置为True ,并且需要显示大量数据,这将迫使表格单元格超出页面高度。>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="Table_Based" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="66519d71-4f27-4833-9a1d-c9b72e811f0c">
<property name="template.engine" value="tabular_template"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<style name="Title" fontName="Times New Roman" fontSize="50" isBold="true"/>
<style name="SubTitle" forecolor="#736343" fontName="Arial" fontSize="18"/>
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Row" mode="Transparent">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style backcolor="#E6DAC3"/>
</conditionalStyle>
</style>
<style name="Table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
<topPen lineWidth="1.0" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="tableDataset" uuid="bcc32bbf-2279-43e0-8149-66ee3e913b5e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
</subDataset>
<subDataset name="Dataset1" uuid="13d74fad-eb9b-446f-a81d-55b8cf6ea0db">
<queryString>
<![CDATA[]]>
</queryString>
</subDataset>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="113" splitType="Stretch">
<staticText>
<reportElement style="Title" x="270" y="0" width="263" height="62" uuid="a080d2ca-6207-4d8e-87c9-d3b61fb495a9"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Report Title]]></text>
</staticText>
<staticText>
<reportElement style="SubTitle" x="303" y="62" width="196" height="22" uuid="0d849401-f944-4163-9df0-f69408a0618a"/>
<textElement>
<font fontName="Times New Roman"/>
</textElement>
<text><![CDATA[Report SubTitle]]></text>
</staticText>
</band>
</title>
<summary>
<band height="112" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<componentElement>
<reportElement stretchType="ElementGroupHeight" x="0" y="0" width="802" height="112" isPrintWhenDetailOverflows="true" uuid="f3767496-0434-4f42-862b-5839d580e423">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Dataset1" uuid="e2733267-966b-4b9b-924a-4bbec63e6b35">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
</datasetRun>
<jr:column width="200" uuid="a3e3c62f-3558-42a1-a701-ad31853970a9">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="200" height="30" uuid="56f1cfe1-76be-4cd4-a4ba-5fe3e56b1a2e"/>
<textElement>
<font size="20"/>
</textElement>
<text><![CDATA[Number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="40" rowSpan="1">
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="ElementGroupHeight" x="0" y="0" width="200" height="40" uuid="bdcc75f5-e9d8-4013-80e7-d22b346d694b"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="300" uuid="e2eaa014-ebfd-4795-b752-476ca2fa8f0b">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="300" height="30" uuid="5d807608-f7ce-4e00-a3e5-5b29bb3228a7"/>
<textElement>
<font size="20"/>
</textElement>
<text><![CDATA[Text]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="40">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="false">
<reportElement positionType="Float" stretchType="ElementGroupHeight" x="0" y="0" width="300" height="40" isPrintWhenDetailOverflows="true" uuid="e7d6d343-cd79-4293-8ccd-0b8af33ea962"/>
<textElement>
<paragraph lineSpacing="1_1_2"/>
</textElement>
<textFieldExpression><![CDATA[UPPER("qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm")]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
例外
net.sf.jasperreports.engine.JRException: java.lang.NullPointerException
at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport(ReportController.java:536)
at com.jaspersoft.studio.editor.preview.view.control.ReportController.access$17(ReportController.java:511)
at com.jaspersoft.studio.editor.preview.view.control.ReportController$1.run(ReportController.java:429)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
Caused by: java.lang.NullPointerException
at net.sf.jasperreports.engine.fill.FillerSubreportParent.isSplitTypePreventInhibited(FillerSubreportParent.java:116)
at net.sf.jasperreports.engine.fill.JRFillBand.isSplitTypePreventInhibited(JRFillBand.java:633)
at net.sf.jasperreports.engine.fill.JRFillBand.isSplitTypePreventInhibited(JRFillBand.java:612)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2589)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:813)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:264)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:110)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:432)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:818)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:61)
at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:221)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
答案 0 :(得分:1)
这是一个可能从6.5.1版开始的错误,但是应该在6.7版中修复。
错误报告为https://community.jaspersoft.com/jasperreports-library/issues/10451
我在JasperSoftStudio v 6.6中测试了您的报告,并且可以确认该错误,但是使用以下代码在Java中使用Jasper Reports lib v 6.7来编译您的报告。
JasperReport report = JasperCompileManager.compileReport("pathTo.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap<String, Object>(), new JREmptyDataSource(1));
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("pdf/SplitTest.pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
无法不能确认该错误
结论,此错误似乎已在6.7版中解决,请确保使用6.7版或6.5.1之前的版本进行正确的测试