Jump to content
Changes to the Jaspersoft community edition download ×

Error on loading .jasper file (Urgent)


ocketje

Recommended Posts

Hello everybody,

I have a problem on my hands and guess what: its about jasper.

This is the situation:

while running the next code:

--- code snippit here ----

public JasperReport getCompliledReport(String reportName) throws JRException{

            // -- initializing the variables
            ResourceLoader loader = new DefaultResourceLoader();
            Resource report = null;
            File compiledReport = null;
            Object jasperReport = null;
           

            // -- load the compiled report as a resource
            report = loader.getResource(JASPER_RESOURCE+reportName);

            try{
                if(report != null){
                    compiledReport = report.getFile();
                }

                // -- load the compiled report and make it a jasper Object
                // -- so jasper reports can work with it.
                jasperReport = JRLoader.loadObject(compiledReport.getAbsolutePath());

            }
            catch(IOException e){
                e.printStackTrace();
            }

            // -- check if the object returned by the JRLoader is of type JasperReport
            if(jasperReport instanceof JasperReport && jasperReport != null){
                    return (JasperReport) jasperReport;
                }
                else
                    throw new JRException(ResourceKeys.DESIGN_LOAD_FAILED);


        }

 --- END OF CODE SNIPPET ----

The exception is thrown at the line in bold.  I get the following stacktrace:

net.sf.jasperreports.engine.JRException: Error loading object from file : C:\branch\target\classes\A6page.jasper
        at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:92)
        at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:64)
        at be.lisis.pos.print.jasper.JasperPrinter.getCompliledReport(JasperPrinter.java:165)
        at be.lisis.pos.print.jasper.JasperPrinter.print(JasperPrinter.java:214)
        at be.lisis.pos.print.jasper.A6Printer.export(A6Printer.java:175)
        at be.lisis.pos.print.jasper.A6Printer.printA6Labels(A6Printer.java:54)
        at be.lisis.pos.workflow.label.PrintWFA.processWorkFlowEvent(PrintWFA.java:201)
        at be.ldc.jawfl.wfm.SecurityContext.dispatch(SecurityContext.java:208)
        at be.ldc.jawfl.wfm.AbstractWorkFlowManager.processWorkFlowEventWithException(AbstractWorkFlowManager.java:358)
        at be.ldc.jawfl.wfm.AbstractWorkFlowManager.processWorkFlowEvent(AbstractWorkFlowManager.java:341)
        at be.ldc.jawfl.gui.AbstractGUIManager.triggerWorkFlowEvent(AbstractGUIManager.java:278)
        at be.ldc.jawfl.gui.AbstractGUIManager$WorkFlowEventListener.actionPerformed(AbstractGUIManager.java:2169)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at be.ldc.jawfl.gui.swing.JWorkFlowButton.fireActionPerformed(JWorkFlowButton.java:114)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6216)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5981)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4583)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2475)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Caused by: java.io.InvalidClassException: java.util.ArrayList; local class incompatible: stream classdesc serialVersionUID = 8664875232659988799, local class serialVersionUID = 8683452581122892189
        at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:88)
        ... 37 more

 

I am also obliged to give a bit more information:

We use jasperreports-maven-plugin to compile any jrxml file in a given source directory. Then i try to load the .jasper file so i can fill it with data and use it.

The problem is not in fetching the resource but in putting the pieces back together after deserialization. it would seem like i have 2 different versions of something (some jar or class or whatever). I find it very odd that the error seems to be about a standard java class (java.util.ArrayList), and as far as i know there is not a single ArrayList used either in the code for printing the report or in the report itself. 

 

Some help on fixing this problem would be greatly appreciated. Any more questions or further information that is required, please ask away. i will be monitoring my thread ofcourse.

This is quite urgent.

Thanks in advance,

Ocketje

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

It looks like you are using one version of JR to compile the reports and a different JR version to run them.

Normally, this should not be a problem, but we need to know which versions you are using, in case we need to fix something.

If you are using old versions, you will just need to upgrade to the latest.

 

Thank you,

Teodor

 

Link to comment
Share on other sites

hello cn73.

Thanks for your reply!

 

Still, i could not yet find a solution. The problem i have is in a class i cant access nor alter.

 

To be precise: it happens in the ObjectInputStream class, at one of the readObject() methods.

 

I cant alter that class. But still, i read the thread that you refer to in your link, and i learned a lot from it.

 

Basically, his problem was the UTF-8 encoding used to encode his URL. I dont use an URL.

 

Still, the UTF-8 encoding makes me think...

 

anyway, thanks for your reply!

Link to comment
Share on other sites

Hello Theodor,

also thanks for your reply.

 

I am absolutely sure that the version of the compiler tool is equal to the version that our software runs. It had crossed my mind already, so i double checked the POM- file to see if the dependencies matched.

 

We use jasperreports version 2.0.1 both in the maven plugin as in our software. This is the POM dependency:

 

<dependency>
            <groupId>jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>2.0.1</version>
</dependency>

 

All of our reports are made with iReports 2.0.2. It wont be easy to upgrade to the latest jasper version, but suppose we do, won't we have problems with our reports that were generated by iReports? The first thing that comes into my mind are deprecated tags or deprecated java code?

Thank you for your reply.

Regards,

Nicholas

Link to comment
Share on other sites

hello all again,

I have upgraded the jasper version to 3.5.3 (in my sandsbox) but i still get the same error.

i dont work with client-server setup here, just maven that builds the project and compiles the jrxml files, then puts it all away in a jar file.

i am sure that the java versions are the same at compile time and at runtime. Everything happens on the same machine btw.

The error occurs n the following piece of code:

jasperReport = JRLoader.loadObject( compiledReport.getAbsolutePath());

The 'compiledReport' variable you see is of the type 'File' and has been fetched as a Resource on which i perform :

resource.getFile(), although i dont think that is part of the cause.

Any more idea's?

 

greetz,

ocketje

Link to comment
Share on other sites

Hello cn73!

 

Thanks for your reply, as it was very helpful. I fixed the problem taking your hint.

You are right and it was a splendid idea. I figured (from the previous link you sent me) that the problem was (the problem of the guy in that specific thread) was an encoding problem. And although i looked at my POM several times, i always missed the fact that there was 1 encoding tag already. So i never thought the problem could be about the same. Thanks mate, you reply was very usefull.

I went looking for some more information and i found the following:

http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding

where it clearly says that changing the encoding for some plugins (especially build plugins) can have a huge impact. And then the pieces of the puzzle somewhat started to connect in my head.

here is the troublesome piece of POM:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <maxmem>128m</maxmem>
                    <encoding>ISO-8859-1</encoding>
                </configuration>

</plugin>

This was the only plugin (of 3 defined plugins) that had an encoding tag to explicitly set an encoding. Now, i dont know what the default is, but i bet it is UTF-8.

So i put the encoding to ISO-8859-1 for all of the defined plugins (being: maven-compiler-plugin, maven-resources-plugin (also build plugin) and jasperreports-maven-plugin (not a build plugin, but very important one considering my goals).

I did a clean and build again (in netbeans), relaunched the project and hooray, it works like a charm now.

 

Thanks for the fast replies!

 

Ocketje

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...