EmiDemi
EmiDemi

Reputation: 61

JasperReports API: calling JasperCompileManager.compileReport (String) method raised the MalformedByteSequenceException exception

public void openReport() {

    try {
        HashMap params = new HashMap();
        params.put("aapor", 19);

        JasperReport jasperReport1 = JasperCompileManager.compileReport("C:/Users/emidemi.emidemi-PC/Documents/NetBeansProjects/FleetManager/src/FleetManager/newReport5.jasper");
        JasperPrint jasperPrint1 = JasperFillManager.fillReport(jasperReport1, params, conn.getConn());

        JRViewer viewer = new JRViewer(jasperPrint1);

    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

Above is my script.

This is my error:

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
BUILD SUCCESSFUL (total time: 7 seconds)

Does anyone know why this is occurring and how to fix it?

Upvotes: 1

Views: 8084

Answers (3)

mroussel
mroussel

Reputation: 11

You are trying to compile a jasper file already compiled. Replace newReport5.jasper by newReport5.jrxml.

If you want to work with jasper file directly, you have to do like this :

JasperReport jasperReport = (JasperReport)JRLoader.loadObject(new File("filename.jasper"));

Upvotes: 1

Angelo Fuchs
Angelo Fuchs

Reputation: 9941

When does this exception occur (Compile or Execution?). Usually that problem means that your input IS NOT UTF-8.

If you are entirely sure that it should be UTF-8 try this: 1. Create a NEW EMPTY file and encode it as UTF-8. 2. Copy the whole text from your old file to the new one. 3. Save the new one and check if it works with the new file. If it does, your old file was not proper UTF-8. 4. If not, post your input file (the jrxml.)

When I have problems like this I try to find the offending character, a HEX Editor helps.

Upvotes: 0

R5498
R5498

Reputation: 154

It's a problem with the character codification. Have you tried changing the encoding line at the beginning of the report?

i.e. for central european alphabet, change:

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

by

<?xml version="1.0" encoding="CP1250"?>

You have a list of different character encoding standards here: http://en.wikipedia.org/wiki/Character_encoding#Common_character_encodings

Hope it works

Upvotes: 2

Related Questions