Error loading object from file

1

Hi All,

This may be simple question but i am unable to move forward further since i am new to jasperreports . Please help me to solve

net.sf.jasperreports.engine.JRException: Error loading object from file : D:\DEV-Apps\EMS-Report\reports\simple.jrxml

here is the code

JasperReport jasperReport = (JasperReport) JRLoader
                    .loadObject(sourceFile);

            File destFile = new File(sourceFile.getParent(),
                    jasperReport.getName() + ".jrprint");

            String destFileName = destFile.toString();

            JasperFillManager.fillReportToFile(jasperReport, destFileName,
                    parameters, dataSource);

            JasperPrintManager.printReport(destFileName, true);

here is the exception getting


net.sf.jasperreports.engine.JRException: Error loading object from file : D:\DEV-Apps\EMS-Report\reports\simple.jrxml
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:127)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:99)
    at com.groups.japser.launch.GroupsJReportExecutor.execute(GroupsJReportExecutor.java:82)
    at com.groups.japser.launch.GroupsJReportExecutor.main(GroupsJReportExecutor.java:142)
Caused by: java.io.StreamCorruptedException: invalid stream header: 3C3F786D
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:58)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:122)


here is the jrxml file (generated through Jasper studio)

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="FeeReceipt" pageWidth="400" pageHeight="400" columnWidth="360" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6e32a6ab-95f0-4757-a8f5-b079e8efca70">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="359" splitType="Stretch">
            <rectangle>
                <reportElement x="0" y="0" width="360" height="359" uuid="27e432b7-74e1-4cb4-9dab-7ffe6fd3e758"/>
            </rectangle>
        </band>
    </detail>
</jasperReport>


Any suggestions are greatly apprciated !!..

Thanks

Dhorrairaajj
 

dorairajm.mca's picture
Joined: Feb 24 2014 - 2:26am
Last seen: 3 years 10 months ago

2 Answers:

-2

What are you putting in "sourceFile"?

Should be be something like below:

BufferedInputStream bufferedInputStream = new BufferedInputStream( new FileInputStream("reports/TestReport.jasper"));

 

hozawa's picture
16159
Joined: Apr 24 2010 - 4:31pm
Last seen: 1 day 12 hours ago

Thank you for your reply,

sourceFile is \reports\simple.jrxml

dorairajm.mca - 4 years 1 month ago
0

That's why. If you're going to specify a path string, you need to use JRXmlLoader.load()

If you want to use JRLoader.loadObject, you have to specify an InputStream as I've mentioned previously.

<span class="pln"></span><span class="typ">JRXmlLoader</span><span class="pun">.</span><span class="pln">load</span><span class="pun"></span>
hozawa's picture
16159
Joined: Apr 24 2010 - 4:31pm
Last seen: 1 day 12 hours ago

Issue is not resolved even after you suggestion. i have seen the source code for the loadObject(File file) method internal it is like

try
{
fis = new FileInputStream(file);
BufferedInputStream bufferedIn = new BufferedInputStream(fis);
ois = new ContextClassLoaderObjectInputStream(jasperReportsContext, bufferedIn);
obj = ois.readObject();
}
catch (IOException e)
{
throw new JRException("Error loading object from file : " + file, e);
}

Issue is at
ois = new ContextClassLoaderObjectInputStream(jasperReportsContext, bufferedIn);

where ContextClassLoaderObjectInputStream object is unable to call the super(in);

Please suggest how to move forward with this issue

Thanks
Dhorrairaajj
Java Lead

dorairajm.mca - 4 years 1 month ago

Finally understood after looking at the source i have to use JasperReport jasperReport = JasperCompileManager.compileReport(fis); instead of JasperReport jasperReport = (JasperReport) JRLoader
.loadObject(sourceFile); since i am try to load jrxml file.

dorairajm.mca - 4 years 1 month ago

Thank you hozawa for you support

dorairajm.mca - 4 years 1 month ago
Feedback
randomness