juniorsatanas 18 de abr. de 2010
posta o codigo aqui , e o erro !
Lord_Byron 18 de abr. de 2010
import java.util.HashMap ;
import net.sf.jasperreports.engine.JRException ;
import net.sf.jasperreports.engine.JasperFillManager ;
import net.sf.jasperreports.engine.JasperPrint ;
import net.sf.jasperreports.view.JasperViewer ;
public class visualizaReport {
public void visualizaReport ()
{
try
{
String getPar1 , getPar2 ;
//frmPrincipal a = new frmPrincipal();
getPar1 = "a1" ;
getPar2 = "a2" ;
HashMap < String , String > parameterMap =
new HashMap < String , String > ();
parameterMap . put ( "par1" , getPar1 );
parameterMap . put ( "par2" , getPar2 );
String arquivo = "D:/Java/NetBeansProjects/testaIReport/src/report.jasper" ;
JasperPrint jp = JasperFillManager . fillReport ( arquivo , parameterMap );
JasperViewer . viewReport ( jp , false );
}
catch ( JRException e )
{
e . printStackTrace ();
}
}
}
<?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= "report" pageWidth= "595" pageHeight= "842" columnWidth= "555" leftMargin= "20" rightMargin= "20" topMargin= "20" bottomMargin= "20" >
<field name= "par1" class= "java.lang.String" />
<field name= "par2" class= "java.lang.String" />
<background>
<band splitType= "Stretch" />
</background>
<title>
<band height= "79" splitType= "Stretch" >
<staticText>
<reportElement x= "132" y= "24" width= "345" height= "29" />
<textElement>
<font fontName= "Arial" size= "14" isBold= "true" />
</textElement>
<text> <![CDATA[Teste de Relatório Utilizando IReport ]]> </text>
</staticText>
</band>
</title>
<pageHeader>
<band height= "35" splitType= "Stretch" />
</pageHeader>
<columnHeader>
<band height= "61" splitType= "Stretch" />
</columnHeader>
<detail>
<band height= "125" splitType= "Stretch" >
<staticText>
<reportElement x= "12" y= "7" width= "66" height= "20" />
<textElement/>
<text> <![CDATA[Parâmetro 1]]> </text>
</staticText>
<staticText>
<reportElement x= "12" y= "37" width= "66" height= "20" />
<textElement/>
<text> <![CDATA[Parâmetro 2]]> </text>
</staticText>
<textField>
<reportElement x= "90" y= "7" width= "100" height= "20" />
<textElement markup= "none" />
<textFieldExpression class= "java.lang.String" > <![CDATA[$F{par1}]]> </textFieldExpression>
</textField>
<textField pattern= "" >
<reportElement x= "90" y= "37" width= "100" height= "20" />
<textElement markup= "none" />
<textFieldExpression class= "java.lang.String" > <![CDATA[$F{par2}]]> </textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height= "45" splitType= "Stretch" />
</columnFooter>
<pageFooter>
<band height= "54" splitType= "Stretch" >
<textField>
<reportElement x= "428" y= "28" width= "80" height= "20" />
<textElement textAlignment= "Right" />
<textFieldExpression class= "java.lang.String" > <![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]> </textFieldExpression>
</textField>
<textField evaluationTime= "Report" >
<reportElement x= "508" y= "28" width= "40" height= "20" />
<textElement/>
<textFieldExpression class= "java.lang.String" > <![CDATA[" " + $V{PAGE_NUMBER}]]> </textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height= "42" splitType= "Stretch" />
</summary>
</jasperReport>
Erro:
E aparece um messagebox dizendo:
betocamargo 18 de abr. de 2010
Lord_Byron chamar ireport não tem erro.
Depois de criado o relatorio pra chama-lo faça o seguinte:
Importe as bibliotecas commons-beanutils, commons-collections, commons-digester, commons-logging, itext, jasperreports, jcommon, groovy
copie o seurelatorio.jasper para onde está o seu .jar
JasperPrint rel = null;
try {
HashMap map = new HashMap();
String arquivoJasper = "seurelatorio.jasper";
try {
rel = JasperFillManager.fillReport(arquivoJasper, map, con);
JasperViewer.viewReport(rel, false);
} catch (JRException ex) {
JOptionPane.showMessageDialog(null, ex);
}
} catch (ExcRepositorio ex) {
JOptionPane.showMessageDialog(null, ex);
}