开发者

Error compiling report java source files

my probleme is: i can't compile my report from java. well i create my page in iReport and i load it from my java code.

here is some of my error:

    5 juin 2011 19:45:47 org.apache.commons.digester.Digester error
GRAVE: Parse Error at line 3 column 408: Attribute "xmlns" must be declared for element type "jasperReport".
org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "jasperReport".
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(XMLDTDValidator.java:1275)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1940)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:764)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1318)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:922)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.commons.digester.Digester.parse(Digester.java:1647)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:238)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:225)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:213)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:167)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:151)
    at gestionstock.Recherche_commande.jButton2ActionPerformed(Recherche_commande.java:258)
    at gestionstock.Recherche_commande.access$300(Recherche_commande.java:36)
    at gestionstock.Recherche_commande$4.actionPerformed(Recherche_commande.java:151)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6263)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6028)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
5 juin 2011 19:45:47 gestionstock.Recherche_commande jButton2ActionPerformed

and here is my java code:

String url = "jdbc:oracle:thin:@localhost:1521:gpsi";
    String user = "gestion";
    String passwd = "password";
    Connection conn = null;

    String reference = this.commande_reference.getText();

    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        conn = DriverManager.getConnection(url, user, passwd);
        Statement stmt = conn.createStatement();

        JasperDesign jasperDesign = JRXmlLoader.load("./lib/report.jrxml");
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        Map parameters = new HashMap();

        parameters.put("ref",reference);        

         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);

        net.sf.jasperreports.view.JasperViewer.viewReport(jasperPrint,false);
        // - Création du rapport au format PDF
        //JasperExportManager.exportReportToPdfFile(jasperPrint, "./lib/report.pdf");

        JOptionPane.showMessageDialog(this , "Opération éffectuée avec succès!", "Terminé" , JOptionPane.INFORMATION_MESSAGE)  ;

    } catch (JRException ex) {
        Logger.getLogger(Recherche_commande.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(this, "erreur : Opération non effectuées " +
                ex.getMessage()  , "Avertissement", JOptionPane.ERROR_MESSAGE);
    } catch (ClassNotFoundException ex) {
        JOptionPane.showMessageDialog(this, "erreur : Opération non effectuées " +
                ex.getMessage()  , "Avertissement", JOptionPane.ERROR_MESSAGE);
    }finally {
        try {
             conn.close();
            } catch (SQLException e) {

                    e.printStackTrace();
            }
    }

and finaly here is my jrxml file called report.jrxml:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<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="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="ref" class="java.lang.String"/>
    <queryString>
        <![CDATA[SELECT
                ASSOCIER."QUANTITE",
                CLIENTS."CLIENTNOM",
                PRODUITS."PRODUITNOM",
                COMMANDES."REFERENCE",
                COMMANDES."COMMANDEDATE",
                CLIENTS."CLIENTPRENOM" AS CLIENTS_CLIENTPRENOM,
                sum(PRODUITS.produitprix*ASSOCIER.quantite)
        FROM
                "COMMANDES" COMMANDES,
                "EMPLOYES" EMPLOYES,
                "CLIENTS" CLIENTS,
                "PAIEMENTS" PAIEMENTS,
                "ASSOCIER" ASSOCIER,
                "PRODUITS" PRODUITS
        WHERE
                COMMANDES.employeid = EMPLOYES.employeid
                and CLIENTS.clientid = COMMANDES.clientid
                and COMMANDES.commandeid = PAIEMENTS.commandeid
                and COMMANDES.commandeid = ASSOCIER.commandeid
                and PRODUITS.produitid = ASSOCIER.produitid
                and COMMANDES.reference = '$P!{ref}'
        GROUP BY
                PRODUITS.produitnom,
                COMMANDES.reference,
                CLIENTS.clientnom,
                CLIENTS.clientprenom,
                EMPLOYES.employenom,
                COMMANDES.commandedate,
                PAIEMENTS.paiementdate,
                ASSOCIER.quantite]]>
    </queryString>
    <field name="QUANTITE" class="java.math.BigDecimal"/>
    <field name="CLIENTNOM" class="java.lang.String"/>
    <field name="PRODUITNOM" class="java.lang.String"/>
    <field name="REFERENCE" class="java.lang.String"/>
    <field name="COMMANDEDATE" class="java.sql.Timestamp"/>
    <field name="CLIENTS_CLIENTPRENOM" class="java.lang.String"/>
    <field name="SUM(PRODUITS.PRODUITPRIX*ASSOCIER.QUANTITE)" class="java.math.BigDecimal"/>
    <group name="REFERENCE">
        <groupExpression><![CDATA[$F{REFERENCE}]]></groupExpression>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="143" splitType="Stretch">
            <staticText>
                <reportElement x="183" y="25" width="222" height="92"/>
                <textElement>
                    <font fontName="Andalus" size="60"/>
                </textElement>
                <text><![CDATA[Facture]]></text>
            </staticText>
            <line>
                <reportElement x="15" y="121" width="527" height="1"/>
                <graphicElement>
                    <pen lineWidth="2.0" lineStyle="Double"/>
                </graphicElement>
            </line>
        </band>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch">
            <staticText>
                <reportElement x="17" y="7" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[Reference :]]></text>
            </staticText>
            <staticText>
                <reportElement x="310" y="9" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[Date :]]></text>
            </staticText>
            <textField>
                <reportElement mode="Transparent" x="127" y="7" width="100" height="20" backcolor="#FFFFFF"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{REFERENCE}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="423" y="7" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.sql.Timestamp"><![CDATA[$F{COMMANDEDATE}]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement x="17" y="10" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[Nom de client :]]></text>
            </staticText>
            <textField>
                <reportElement x="127" y="10" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{CLIENTNOM}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="307" y="10" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[Prenom de  client :]]></text>
            </staticText>
            <textField>
                <reportElement x="423" y="10" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{CLIENTS_CLIENTPRENOM}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="-19" y="30" width="595" height="1" forecolor="#666666"/>
            </line>
            <staticText>
                <reportElement mode="Opaque" x="323" y="41" width="143" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
                <textElement textAlignment="Center">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[SUM(PRODUITS.PRODUITPRIX*ASSOCIER.QUANTITE)]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="204" y="41" width="119" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
                <textElement textAlignment="Center">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[QUANTITE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="73" y="41" width="131" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
                <textElement textAlignment="Center">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[PRODUITNOM]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="49" splitType="Stretch">
            <textField>
                <reportElement mode="Transparent" x="73" y="0" width="131" height="20" backcolor="#9999FF"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{PRODUITNOM}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="324" y="0" width="142" height="20"/>
                <textElement/>
                <textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{SUM(PRODUITS.PRODUITPRIX*ASSOCIER.QUANTITE)}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="204" y="0" width="120" height="20"/>
                <textElement/>
                <textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{QUANTITE}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="73" y="0" width="393" height="1"/>
            </line>
            <line>
                <reportElement x="204" y="1" width="1" height="19"/>
            </line>
        </band>
    </detail>
    <pageFooter>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement mode="Opaque" x="0" y="15" width="515" height="13" backcolor="#E6E6E6"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement mode="Opaque" x="515" y="15" 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="15" width="100" height="13"/>
                <textElement/>
                <textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>

for i开发者_开发问答nformation im using:

iReport3.4.7
jasperreports-1.2.1.jar
iText-2.1.7.jar
commons-logging-api-1.0.2.jar
commons-logging-1.0.2.jar
commons-digester-1.7.jar
commons-collections-2.1.jar
commons-beanutils-1.5.jar
groovy-all-1.5.5.jar

I'll be thankfull !!!

after deleting the xmlns, i have that error:

5 juin 2011 21:18:10 org.apache.commons.digester.Digester error
GRAVE: Parse Error at line 62 column 30: Attribute "splitType" must be declared for element type "band".
org.xml.sax.SAXParseException: Attribute "splitType" must be declared for element type "band".
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)


Instead of using both the DTD and the XML schema, stick to the DTD alone. In other words, instead of having the following lines in your JRXML file:

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<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="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">

you should instead have:

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport>

Update

Going by the fact that iReport 3.4.7 was being used to generate the JRXML file, to be used against JasperReports 1.2.1, it was evident that the generated JRXML file would not be validated correctly. Therefore, the fix is to use compatible versions of iReport and JasperReports.


I resolved this error by adding the jdk bin directory into the environmental variables. Hope this helps someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜