net.sf.jasperreports.engine.JRException:无法从位置加载对象:C:\ ..... \ src \ Formularios \ Subreporte 1.jasper

时间:2013-05-10 18:28:59

标签: java path jasper-reports

错误:

  

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óndeAspirantes。里面的子文件夹和文件是:

  • 构建
  • DIST
  • nbproject文件
  • SRC
    • BD
      • ConexionMySQL.java
    • Formularios
      • Administrador.form
      • Administrador.java
      • Aspirantes.form
      • Aspirantes.java
      • Avisos.form
      • Avisos.java
      • ClaseiReport.java
      • Conexion.java
      • Principal.form
      • Principal.java
      • Reporte.jaasper
      • Reporte.jrxml
      • Subreporte 1.jasper
      • Subreporte 1.jrxml
      • Subreporte 2.jasper
      • Subreporte 2.jrxml
  • 的build.xml
  • MANIFEST.MF
  • MySQL Connector.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>

0 个答案:

没有答案