Danilo M.
Danilo M.

Reputation: 1592

JRException: Invalid byte 1 of 1-byte UTF-8 sequence

I am trying to generate a report using Jasper Reports, but I am getting the following error.

net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

I am using this Java code:

    List<Aluno> lista = alunoService.findAll();
    String path = req.getSession().getServletContext().getRealPath("WEB-INF");
    JasperReport report = JasperCompileManager.compileReport(path + "/relatorios/aluno.jasper");
    JasperPrint print = JasperFillManager.fillReport(report, null, new JRBeanCollectionDataSource(lista));
    JasperExportManager.exportReportToPdfFile(print, path + "/relatorios/teste.pdf");

The error is ocurring when try to compile report:

JasperReport report = JasperCompileManager.compileReport(path + "/relatorios/aluno.jasper");

The aluno.jrxml file is in UTF-8 enconding:

<?xml version="1.0" encoding="UTF-8"?>

I've researched this problem, but they all say that the reason is because the jrxml filw is not in UTF-8 enconding. If anyone could help me, I really thank.

Java code using aluno.jrxml

    List<Aluno> lista = alunoService.findAll();
    String path = req.getSession().getServletContext().getRealPath("WEB-INF");
    JasperDesign design = JRXmlLoader.load(path + "/relatorios/aluno.jrxml");
    JasperReport report = JasperCompileManager.compileReport(design);
    JasperPrint print = JasperFillManager.fillReport(report, null, new JRBeanCollectionDataSource(lista));
    JasperExportManager.exportReportToPdfFile(print, path + "/relatorios/teste.pdf"

Upvotes: 1

Views: 11749

Answers (1)

morgano
morgano

Reputation: 17422

The fact that you have <?xml version="1.0" encoding="UTF-8"?> at the beginning of your file doesn't mean that the file is actually stored in UTF-8 encoding, that just means "I swear this file has this encoding".

Do you have in your file characters other than the classic ASCII? (something like the Spanish N with a tilde on it?)

Try opening your file with a decent editor and save it again, choosing explicitly the encoding as UTF-8 AND after that have a look at your special characters inside your file to see if they are still the same.

Upvotes: 1

Related Questions