0

错误:

net.sf.jasperreports.engine.JRException:无法从位置加载对象:C:\Users\Juan Ortega\Documents\NetBeansProjects\Selección de Aspirantes\src\Formularios\Subreporte 1.jasper

保存所有内容的文件夹是 C:\Users\Juan Ortega\Documents\NetBeansProjects\Selección de Aspirantes。里面的子文件夹和文件是:

  • 建造
  • 距离
  • NB项目
  • 源代码
    • BD
      • ConexionMySQL.java
    • 公式
      • 管理员表格
      • 管理员.java
      • Aspirantes.form
      • Aspirantes.java
      • Avisos.form
      • Avisos.java
      • 分类报告.java
      • Conexion.java
      • 主体形式
      • 校长.java
      • 报告.jaasper
      • 报告.jrxml
      • 子报表 1.jasper
      • 子报表 1.jrxml
      • 子报表 2.jasper
      • 子报表 2.jrxml
  • 构建.xml
  • 清单文件
  • MySQL 连接器.jar

我清理并构建项目,以便其他用户可以使用它。当他们从控制台运行生成的 Java 可执行文件时,他们从上面得到错误。类内的代码ClaseiReport.java如下:

public class ClaseiReport {
private Conexion con = new Conexion();

public void reporte() {
    JasperReport reporte;
    JasperPrint reporte_view;
    try {
        URL  in = this.getClass().getResource("Reporte.jasper");
        reporte = (JasperReport) JRLoader.loadObject(in);
        reporte_view = JasperFillManager.fillReport(reporte, new HashMap(), con.getConnection());
        JasperViewer.viewReport(reporte_view,false);
        con.desconectar();
    }
    catch (JRException e){
        e.printStackTrace();
    }
}
}

我想该错误与文件 Reporte.jrxml 上的完整路径有关:

<defaultValueExpression><![CDATA["C:\\Users\\Juan
Ortega\\Documents\\NetBeansProjects\\Selección de Aspirantes\\src\\Formularios\\"]]></defaultValueExpression>

我不知道如何确保 .jar 在另一台计算机上使用它时找到子报表。我在论坛上看到了很多关于这个错误的问题,但我不知道如何解决它。

下一个代码块包含在主报告 (Reporte.jrxml) 中。我应该对<defaultValueExpression>变量进行什么更改?

<?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="Reporte" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["C:\\Users\\Juan Ortega\\Documents\\NetBeansProjects\\Selección de Aspirantes\\src\\Formularios\\"]]></defaultValueExpression>
</parameter>
<queryString language="SQL">
    <![CDATA[SELECT * FROM datos WHERE ficha = (SELECT max(ficha)FROM datos)]]>
</queryString>
<field name="ficha" class="java.lang.Integer">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="apellido1" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="apellido2" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="nombre" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="carrera" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
    <band/>
</background>
<title>
    <band height="70">
        <frame>
            <reportElement mode="Opaque" x="-20" y="-20" width="595" height="90" backcolor="#006699"/>
            <staticText>
                <reportElement mode="Transparent" x="20" y="30" width="555" height="43" forecolor="#FFFFFF"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14" isBold="true"/>
                </textElement>
                <text><![CDATA[SUBSECRETARÍA DE EDUCACIÓN MEDIA SUPERIOR. DIRECCIÓN GENERAL DE EDUCACIÓN TECNOLÓGICA INDUSTRIAL]]></text>
            </staticText>
        </frame>
    </band>
</title>
<pageHeader>
    <band height="98">
        <staticText>
            <reportElement mode="Transparent" x="0" y="58" width="268" height="20" forecolor="#000000" backcolor="#CCFFFF"/>
            <textElement verticalAlignment="Middle">
                <font size="14"/>
            </textElement>
            <text><![CDATA[Clave de la Escuela: 18DCTO100F]]></text>
        </staticText>
        <staticText>
            <reportElement mode="Transparent" x="268" y="58" width="287" height="20" forecolor="#000000" backcolor="#CCFFFF"/>
            <textElement verticalAlignment="Middle">
                <font size="14"/>
            </textElement>
            <text><![CDATA[Periodo:]]></text>
        </staticText>
        <subreport>
            <reportElement x="327" y="58" width="228" height="20"/>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "Subreporte 1.jasper"]]></subreportExpression>
        </subreport>
        <staticText>
            <reportElement mode="Opaque" x="0" y="11" width="555" height="36" forecolor="#000000" backcolor="#CCFFFF"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="14" isBold="true"/>
            </textElement>
            <text><![CDATA[FICHA DE PRE-REGISTRO PARA EL EXAMEN DE INGRESO AL CETis 100]]></text>
        </staticText>
        <line>
            <reportElement x="0" y="88" width="555" height="1" forecolor="#CCFFFF"/>
        </line>
        <line>
            <reportElement x="0" y="93" width="555" height="1" forecolor="#CCCCCC"/>
        </line>
    </band>
</pageHeader>
<detail>
    <band height="425">
        <textField isStretchWithOverflow="true">
            <reportElement x="43" y="11" width="111" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12"/>
            </textElement>
            <textFieldExpression class="java.lang.Integer"><![CDATA[$F{ficha}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement x="138" y="41" width="115" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12"/>
            </textElement>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{apellido1}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement x="253" y="41" width="115" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12"/>
            </textElement>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{apellido2}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement x="368" y="41" width="115" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12"/>
            </textElement>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{nombre}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement x="113" y="71" width="255" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12"/>
            </textElement>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{carrera}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement x="0" y="11" width="43" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[Ficha:]]></text>
        </staticText>
        <staticText>
            <reportElement x="0" y="41" width="138" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[Nombre del Solicitante:]]></text>
        </staticText>
        <staticText>
            <reportElement x="0" y="71" width="113" height="20"/>
            <textElement verticalAlignment="Middle">
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[Carrera Solicitada:]]></text>
        </staticText>
        <staticText>
            <reportElement mode="Opaque" x="0" y="117" width="555" height="29" forecolor="#000000" backcolor="#FFFFCC"/>
            <textElement verticalAlignment="Middle">
                <font size="12" isBold="false"/>
            </textElement>
            <text><![CDATA[*** Aviso ***]]></text>
        </staticText>
        <subreport>
            <reportElement x="0" y="156" width="555" height="250"/>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "Subreporte 2.jasper"]]></subreportExpression>
        </subreport>
        <staticText>
            <reportElement mode="Opaque" x="0" y="266" width="555" height="29" forecolor="#000000" backcolor="#FFFFCC"/>
            <textElement verticalAlignment="Middle">
                <font size="12" isBold="false"/>
            </textElement>
            <text><![CDATA[*** Recomendaciones ***]]></text>
        </staticText>
        <rectangle>
            <reportElement mode="Transparent" x="454" y="9" width="100" height="100" forecolor="#CCCCCC"/>
            <graphicElement>
                <pen lineStyle="Dashed"/>
            </graphicElement>
        </rectangle>
    </band>
</detail>
<columnFooter>
    <band/>
</columnFooter>
<pageFooter>
    <band height="17">
        <textField>
            <reportElement mode="Opaque" x="0" y="4" width="515" height="13" backcolor="#E6E6E6"/>
            <textElement textAlignment="Right"/>
            <textFieldExpression class="java.lang.String"><![CDATA["Página "+$V{PAGE_NUMBER}+" de"]]></textFieldExpression>
        </textField>
        <textField evaluationTime="Report">
            <reportElement mode="Opaque" x="515" y="4" width="40" height="13" backcolor="#E6E6E6"/>
            <textElement/>
            <textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
        </textField>
        <textField pattern="EEEEE dd MMMMM yyyy">
            <reportElement x="0" y="4" width="100" height="13"/>
            <textElement/>
            <textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
        </textField>
    </band>
</pageFooter>
<summary>
    <band/>
</summary>
</jasperReport>
4

0 回答 0