Tenho um método que gera um relatório pdf utilizando JRDataSource da seguinte maneira.
parte do método que gera o data source
[code] List abstractBeanList = getLigsBean(entrada);
JRDataSource source = getLigacaoDataSource(abstractBeanList);
//JRBeanCollectionDataSource source = new JRBeanCollectionDataSource(abstractBeanList);
String filePath2 = filePath.replace(".xls", ".pdf");
JasperPrint print = JasperFillManager.fillReport(getLigReportFile(),null, source);
JasperExportManager.exportReportToPdfFile(print, filePath2);[/code]
[code] private List getLigsBean(List ligacoes) throws Exception {
List beans = new ArrayList();
for (int i = 0; i < ligacoes.size(); i++) {
EntradaAbstrata lig = ligacoes.get(i);
LigacaoBean bean = new LigacaoBean();
if (lig.getNumeroDeOrigem() != null) {
bean.setNumeroDeOrigem(lig.getNumeroDeOrigem().toString());
} else {
bean.setNumeroDeOrigem("-");
}
if (lig.getDestino() != null && !lig.getDestino().toString().equals("")) {
bean.setNumeroDeDestino(lig.getDestino().toString());
} else {
bean.setNumeroDeDestino("-");
}
if (lig.getDataOrigemLigacao() != null) {
SimpleDateFormat formatador = new SimpleDateFormat("dd/MM/yyyy");
String f = formatador.format(lig.getDataOrigemLigacao());
bean.setData(f);
} else {
bean.setData("-");
}
if (lig.getDataOrigemLigacao() != null) {
SimpleDateFormat formatador = new SimpleDateFormat("HH:mm");
String f = formatador.format(lig.getDataOrigemLigacao());
bean.setHora(f);
} else {
bean.setHora("-");
}
try {
if (lig.getDuracaoLigacaoHoras() != null) {
bean.setDuracao(lig.getDuracaoLigacaoHoras());
} else {
bean.setDuracao("-");
}
} catch (Exception exc) {
bean.setDuracao("-");
}
if (lig.getCusto() != null) {
bean.setValor(String.valueOf(lig.getCusto()));
} else {
bean.setValor(String.valueOf(0.0));
}
if (lig.getTipoDeLigacao() != null) {
if (lig.getTipoDeLigacao().length() > 70) {
bean.setTipo(lig.getTipoDeLigacao());
} else {
bean.setTipo(lig.getTipoDeLigacao());
}
} else {
bean.setTipo("-");
}
beans.add(bean);
}
Collections.sort(beans, new Comparators.CompareByNumberAndValueLigacaoBean());
return beans;
}
private JRDataSource getLigacaoDataSource(List<AbstractBean> abstractBeanList) {
return new LigacaoDataSource(abstractBeanList);
}[/code]
métodos chamados no método acima
[code]public class LigacaoDataSource implements JRDataSource {
private Iterator<AbstractBean> iterator;
private LigacaoBean bean;
public LigacaoDataSource(List<AbstractBean> beans) {
iterator = beans.iterator();
}
public boolean next() throws JRException {
boolean next = iterator.hasNext();
if (next) {
bean = (LigacaoBean) iterator.next();
}
return next;
}
public Object getFieldValue(JRField jrf) throws JRException {
if (jrf.getName().equals("numeroDeOrigem")) {
return bean.getNumeroDeOrigem();
}
if (jrf.getName().equals("numeroDeDestino")) {
return bean.getNumeroDeDestino();
}
if (jrf.getName().equals("hora")) {
return bean.getHora();
}
if (jrf.getName().equals("data")) {
return bean.getData();
}
if (jrf.getName().equals("duracao")) {
return bean.getDuracao();
}
if (jrf.getName().equals("valor")) {
return bean.getValor();
}
if (jrf.getName().equals("tipo")) {
return bean.getTipo();
}
return null;
}
}[/code] classe que implementa o JRDataSource
[code]public class LigacaoBean implements AbstractBean {
private String NUMERODEORIGEM;
private String NUMERODESTINO;
private String DATA;
private String HORA;
private String DURACAO;
private String VALORTOTAL;
private String TIPO;
public LigacaoBean() {
}
public LigacaoBean(String numeroDeOrigem, String numeroDeDestino, String data, String hora, String duracao, String valor, String tipo) {
this.NUMERODEORIGEM = numeroDeOrigem;
this.NUMERODESTINO = numeroDeDestino;
this.DATA = data;
this.HORA = hora;
this.DURACAO = duracao;
this.VALORTOTAL = valor;
this.TIPO = tipo;
}
public String getNumeroDeDestino() {
return NUMERODESTINO;
}
public void setNumeroDeDestino(String numeroDeDestino) {
this.NUMERODESTINO = numeroDeDestino;
}
public String getNumeroDeOrigem() {
return NUMERODEORIGEM;
}
public void setNumeroDeOrigem(String numeroDeOrigem) {
this.NUMERODEORIGEM = numeroDeOrigem;
}
public String getTipo() {
return TIPO;
}
public void setTipo(String tipo) {
this.TIPO = tipo;
}
public String getValor() {
return VALORTOTAL;
}
public void setValor(String valor) {
this.VALORTOTAL = valor;
}
public String getData() {
return DATA;
}
public void setData(String data) {
this.DATA = data;
}
public String getDuracao() {
return DURACAO;
}
public void setDuracao(String duracao) {
this.DURACAO = duracao;
}
public String getHora() {
return HORA;
}
public void setHora(String hora) {
this.HORA = hora;
}
}[/code]
meu objeto bean
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at net.sf.jasperreports.engine.fill.JRFillTextField.getFormat(JRFillTextField.java:706)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:394)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:368)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:258)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:499)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2036)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:760)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:270)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:84)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:540)
Erro gerado.
Já tentei de tudo, e tenho métodos que fazem a mesma coisa para outros relatórios que funcionam.
Se alguem puder dar uma luz.
A o xml do relatório é esse.
<?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="TotalReport" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.1000000000000025"/>
<property name="ireport.x" value="49"/>
<property name="ireport.y" value="0"/>
<style name="table">
<box>
<pen lineWidth="0.25" 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>
<subDataset name="Table Dataset 1"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="data" class="java.lang.String">
<fieldDescription><![CDATA[data]]></fieldDescription>
</field>
<field name="duracao" class="java.lang.String">
<fieldDescription><![CDATA[duracao]]></fieldDescription>
</field>
<field name="hora" class="java.lang.String">
<fieldDescription><![CDATA[hora]]></fieldDescription>
</field>
<field name="numeroDeDestino" class="java.lang.String">
<fieldDescription><![CDATA[numeroDeDestino]]></fieldDescription>
</field>
<field name="numeroDeOrigem" class="java.lang.String">
<fieldDescription><![CDATA[numeroDeOrigem]]></fieldDescription>
</field>
<field name="tipo" class="java.lang.String">
<fieldDescription><![CDATA[tipo]]></fieldDescription>
</field>
<field name="valor" class="java.lang.String">
<fieldDescription><![CDATA[valor]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band height="36" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="15" splitType="Stretch">
<staticText>
<reportElement style="table" mode="Transparent" x="95" y="0" width="183" height="15"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Número de Destino]]></text>
</staticText>
<staticText>
<reportElement style="table" mode="Transparent" x="0" y="0" width="95" height="15"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Número de Origem]]></text>
</staticText>
<staticText>
<reportElement style="table" mode="Transparent" x="278" y="0" width="64" height="15"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Data]]></text>
</staticText>
<staticText>
<reportElement style="table" mode="Transparent" x="342" y="0" width="64" height="15"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Hora]]></text>
</staticText>
<staticText>
<reportElement style="table" mode="Transparent" x="508" y="0" width="92" height="15"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Valor Total]]></text>
</staticText>
<staticText>
<reportElement style="table" mode="Transparent" x="600" y="0" width="92" height="15"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Tipo de Ligação]]></text>
</staticText>
<staticText>
<reportElement style="table" mode="Transparent" x="406" y="0" width="102" height="15"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Duração]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="18" splitType="Stretch">
<textField pattern="" isBlankWhenNull="false">
<reportElement style="table" stretchType="RelativeToTallestObject" mode="Transparent" x="95" y="0" width="183" height="17"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{numeroDeDestino}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="false">
<reportElement style="table" stretchType="RelativeToTallestObject" mode="Transparent" x="0" y="0" width="95" height="17"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{numeroDeOrigem}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="false">
<reportElement style="table" stretchType="RelativeToTallestObject" mode="Transparent" x="278" y="0" width="64" height="17"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{data}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="false">
<reportElement style="table" mode="Transparent" x="342" y="0" width="64" height="17"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{hora}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement style="table" x="508" y="0" width="92" height="17"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{valor}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="false">
<reportElement style="table" x="600" y="0" width="92" height="17"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{tipo}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="false">
<reportElement style="table" mode="Transparent" x="406" y="0" width="102" height="17"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{duracao}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>