当表中任何列标题单元格中的TextField的内容大于页面高度时,为什么表会引发异常?

时间:2018-09-24 21:23:28

标签: jasper-reports infinite-loop

当表格单元格(文本字段)的内容较大时,Jasperreports Studio会在预览期间引发运行时错误。这里重要的是,“文本”字段需要将其“ <溢出时拉伸”属性设置为“真”

以下是引发的异常:

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRRuntimeException: Infinite loop creating new page due to column header overflow.
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: net.sf.jasperreports.engine.JRRuntimeException: Infinite loop creating new page due to column header overflow.
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnHeader(JRVerticalFiller.java:534)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:154)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:822)
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)

可以以多种方式重现此问题,但我使用的是最简单的方案。我已经附上了简单的jrxml文件以供参考。我使用了一个带有空数据集的表。我已经使用文本字段表达式来显示数据。我已将isStretchWithOverflow设置为true。

JRXML

<?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.grid.JSSGridBagLayout"/>
        <componentElement>
            <reportElement stretchType="ContainerBottom" 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="05c4f663-c370-4c53-b332-ae9dfb9590e0"/>
                <jr:column width="170" uuid="a3e3c62f-3558-42a1-a701-ad31853970a9">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                    <jr:tableHeader style="Table_TH" height="30" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="170" height="30" uuid="a5ddd2d9-992d-41d2-a7d0-4cc7ec29350b"/>
                            <textElement>
                                <font size="20"/>
                            </textElement>
                            <text><![CDATA[Number]]></text>
                        </staticText>
                    </jr:tableHeader>
                    <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                        <textField>
                            <reportElement positionType="Float" stretchType="ElementGroupHeight" x="0" y="0" width="170" height="30" uuid="b4f24d97-8dbe-42e8-81a8-34fb336eabef"/>
                            <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
                        </textField>
                    </jr:columnHeader>
                    <jr:detailCell style="Table_TD" height="40" rowSpan="1"/>
                </jr:column>
                <jr:column width="173" uuid="e2eaa014-ebfd-4795-b752-476ca2fa8f0b">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:tableHeader style="Table_TH" height="30" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="173" height="30" uuid="b80ae7ce-3491-45cd-963d-8638f03a3891"/>
                            <textElement>
                                <font size="20"/>
                            </textElement>
                            <text><![CDATA[Text]]></text>
                        </staticText>
                    </jr:tableHeader>
                    <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement positionType="Float" x="0" y="0" width="173" height="30" isPrintWhenDetailOverflows="true" uuid="a2647f94-9054-4efd-904e-0850eead4cdf"/>
                            <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:columnHeader>
                    <jr:detailCell style="Table_TD" height="40">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</summary>

在类似情况下,Jasperreports服务器会引发不同的运行时异常: 它似乎是某种错误。任何帮助都是很大的帮助。

2018-09-21 17:03:26,667 ERROR RenderViewExceptionInterceptor,http-nio-8080-exec-8:55 - Internal server error occurred. Please contact your system administrator.
java.lang.NullPointerException
at net.sf.jasperreports.components.table.util.TableUtil.getAllColumns(TableUtil.java:162)
at net.sf.jasperreports.components.headertoolbar.json.HeaderToolbarElementJsonHandler.getColumnGroupsData(HeaderToolbarElementJsonHandler.java:832)
at net.sf.jasperreports.components.headertoolbar.json.HeaderToolbarElementJsonHandler.getJsonFragment(HeaderToolbarElementJsonHandler.java:237)
at net.sf.jasperreports.engine.export.JsonExporter.exportGenericElement(JsonExporter.java:487)

1 个答案:

答案 0 :(得分:1)

您需要重新设计报告。

当前,您希望在每个页面上都有一个列标题,但是您的列标题不适合页面,所以会发生这种情况。

  1. 创建列标题(因为表格或新页面的开始)
  2. 中断至新页面(因为不合适)。
  3. 从新页面转到1。
  

net.sf.jasperreports.engine.JRRuntimeException:由于列标题溢出,无限循环创建新页面。

您的解决方案可以全部是通过缩小文本,放大列或截断文本以使其适合页面。