When I was running report in ireport I got output correctly. But when I compile jrml file through java code I am getting error like
org.xml.sax.SAXParseException; lineNumber: 63; columnNumber: 38; cvc-complex-type.2.4.d: Invalid content was found starting with element 'paragraph'. No child element is expected at this point.
Here is my java code
public byte[] generate(String path,String fileName,String type,String query,HashMap<String,Object> param){
byte[] output=null;
Connection con=JdbcUtil.getJdbcConnection();
JasperDesign jasperDesign=null;
JasperReport jasperReport=null;
System.out.println("Exec RT");
try{
jasperDesign = JRXmlLoader.load(path+"\\"+fileName);
}catch(Exception e1){System.out.println("t0:"+e1.getMessage());
System.out.println("RTMap:"+param);
try{
JRDesignQuery nQuery=new JRDesignQuery();
nQuery.setText(query);
jasperDesign.setQuery(nQuery);
}catch(Exception e){System.out.println("t1:"+e.getMessage());}
System.out.println("Compiling Report Designs");
try{
jasperReport = JasperCompileManager.compileReport(path+"\\"+fileName);
}catch(Exception e5){}
JasperPrint jasperPrint=null;
try{
jasperPrint = JasperFillManager.fillReport(jasperReport, param, con);
}catch(Exception e){System.out.println("RT0:"+e.getMessage());}
String fName=fileName.substring(0,fileName.indexOf("."));
JRExporter exporter= null;
try{
if(type.equalsIgnoreCase("pdf")){
output=JasperExportManager.exportReportToPdf(jasperPrint);
}else if(type.equalsIgnoreCase("html")){
exporter = new JRHtmlExporter();
}else if(type.equalsIgnoreCase("rtf")){
exporter=new JRRtfExporter();
}else if(type.equalsIgnoreCase("xls")){
exporter = new JRXlsExporter();
}else if(type.equalsIgnoreCase("csv")){
exporter=new JRCsvExporter();
}
output = exportReportToBytes(jasperPrint, exporter);
}catch(Exception er){System.out.println("RT2:"+er.getMessage());
}
}
return output;
}
I have one sub report and one main report. I used ireport 4.0.2. My jrxml file (offerLetter.jrxml):
<?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="offerLetter" language="groovy" pageWidth="595" pageHeight="1417" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 2_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 3_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 4">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 4_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 4_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 4_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 5">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 5_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 5_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 5_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 6">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 6_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 6_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 6_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 7">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 7_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 7_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 7_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<parameter name="appid" class="java.lang.Integer">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="logopath" class="java.lang.String"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT offer.INT_OFFERID,ecat.CHR_CATEGORYNAME,CONCAT(year(CURRENT_TIMESTAMP),CONCAT('-',year(CURRENT_TIMESTAMP)+1)) ayear,
DATE_FORMAT(CURRENT_DATE,'%d-%b-%y'),
CONCAT( if(app.CHR_GENDER='Male','Mr. ', if(app.CHR_MARITALSTATUS ='M','Mrs.' ,'Ms.') ),' ',app.CHR_APPNAME) salute,office.CHR_OFFICENAME,desig.CHR_DESIGNAME,
DATE_ADD(CURDATE(),INTERVAL 3 DAY) joining,
FUN_GET_takehome(hal.INT_APPID) takehome
FROM
hrm_t_allowance hal,hrm_m_application app,hrm_t_offerletter offer,com_m_office office,com_m_desig desig,com_m_employeecategory ecat
WHERE hal.INT_APPID=offer.INT_APPID AND app.INT_APPID=offer.INT_APPID AND offer.INT_DESIGID=desig.INT_DESIGID AND
offer.INT_OFFICEID=office.INT_OFFICEID AND hal.INT_APPID=$P{appid}
AND ecat.INT_EMPLOYEECATEGORYID=offer.INT_CATEGORY;]]>
</queryString>
<field name="INT_OFFERID" class="java.lang.Integer"/>
<field name="CHR_CATEGORYNAME" class="java.lang.String"/>
<field name="ayear" class="java.lang.String"/>
<field name="DATE_FORMAT(CURRENT_DATE,'%d-%b-%y')" class="java.lang.String"/>
<field name="salute" class="java.lang.String"/>
<field name="CHR_OFFICENAME" class="java.lang.String"/>
<field name="CHR_DESIGNAME" class="java.lang.String"/>
<field name="joining" class="java.sql.Date"/>
<field name="takehome" class="java.lang.Integer"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="84" splitType="Stretch">
<image>
<reportElement x="171" y="-1" width="360" height="58"/>
<imageExpression class="java.lang.String"><![CDATA[$P{logopath}]]></imageExpression>
</image>
<staticText>
<reportElement x="218" y="57" width="128" height="27"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[OFFER LETTER]]></text>
</staticText>
</band>
</title>
<summary>
<band height="203" splitType="Stretch">
<textField>
<reportElement x="12" y="0" width="543" height="14"/>
<box leftPadding="0" rightPadding="0"/>
<textElement verticalAlignment="Top" markup="html">
<font fontName="Times New Roman" size="10"/>
<paragraph lineSpacing="1_1_2"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["CARE/OFFER-"+$F{INT_OFFERID}+"/"+$F{CHR_CATEGORYNAME}+"/"+$F{ayear}+"."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="12" y="14" width="100" height="14"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATE_FORMAT(CURRENT_DATE,'%d-%b-%y')}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="12" y="38" width="57" height="15"/>
<textElement>
<font isBold="false"/>
</textElement>
<text><![CDATA[To,]]></text>
</staticText>
<textField>
<reportElement x="12" y="53" width="100" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{salute}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="12" y="68" width="206" height="13"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{CHR_OFFICENAME}+","]]></textFieldExpression>
</textField>
<textField>
<reportElement x="12" y="98" width="543" height="14"/>
<box leftPadding="0" rightPadding="0"/>
<textElement verticalAlignment="Top" markup="html">
<font fontName="Times New Roman" size="10"/>
<paragraph lineSpacing="1_1_2"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Dear."+$F{salute}+","]]></textFieldExpression>
</textField>
<textField>
<reportElement x="12" y="112" width="543" height="16"/>
<box leftPadding="0" rightPadding="0"/>
<textElement verticalAlignment="Top" markup="html">
<font fontName="Times New Roman" size="10"/>
<paragraph lineSpacing="1_1_2"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["We are pleased to offer the post of "+" \""+$F{CHR_DESIGNAME}+" \" "+" in our organisation at "+"\""+$F{CHR_OFFICENAME}+"\""+"."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="12" y="128" width="543" height="12"/>
<box leftPadding="0" rightPadding="0"/>
<textElement verticalAlignment="Top" markup="html">
<font fontName="Times New Roman" size="10"/>
<paragraph lineSpacing="1_1_2"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["You are expected to join us on or before "+$F{joining}+" failing with this offer is not valid. Your salary details as mentioned bellow "]]></textFieldExpression>
</textField>
<subreport>
<reportElement positionType="Float" x="12" y="140" width="41" height="38"/>
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="appid">
<subreportParameterExpression><![CDATA[$P{appid}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="logopath">
<subreportParameterExpression><![CDATA[$P{logopath}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "offerLetter_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</summary>
</jasperReport>
I got the result by deleting duplicated jasperreport jar files from the project