Jump to content

Recommended Posts

Posted

Hi everybody.

I try to write JRVirtualPrintPage object into OutputStream in order to wite it to persistence file.

But when i read  from InputStream, i couldn't load a class which i defined when perform percentile calculation

My code at below:

private void writePages() throws IOException, JRException {       OutputStream pos = new OutputStream();        ObjectOutputStream oos = new ObjectOutputStream(pos);               List pages = print.getPages();        numPages = pages == null ? 0 : pages.size();        writeInt(numPages);               pageFilePointers = new long[pages.size()];        long pfpOffset = writeObject(pageFilePointers);        for(int i = 0; i < numPages; i++)        {            if (interrupted)                return;                       if (Thread.currentThread().isInterrupted())            {                throw new JRException("Current thread interrupted.");            }            JRVirtualPrintPage vpage = (JRVirtualPrintPage)pages.get(i);                  oos.writeObject(vpage);                       for (JRPrintElement jrPrintElement : elements) {                oos.writeObject(jrPrintElement);            }                       pageFilePointers[i] = writeBytes(pos.getBytes());        }        long saveFP = file.getFilePointer();        file.seek(pfpOffset);        writeObject(pageFilePointers);        file.seek(saveFP);    }    private void readPages() throws IOException, ClassNotFoundException {        int numPages = readInt();        pageFilePointers = (long[])readObject();        AJPersistenceInputStream pis = new AJPersistenceInputStream();        file.seek(pageFilePointers[0]);        byte[] pageBytes = readBytes();        pis.reset(pageBytes);        ObjectInputStream ois = new ObjectInputStream(pis);        JRVirtualPrintPage page = (JRVirtualPrintPage)ois.readObject();                      if (startIndex == endIndex) {            for(int i=1; i<=startIndex; i++)                page = getPrintPage(pis, ois, i);            print.addPage(page);        }        else {            endIndex = Math.min(endIndex, pageFilePointers.length-1);            for(int i=0; i<=endIndex; i++) {                if (i>0)    // else already read page index == 0                    page = getPrintPage(pis, ois, i);                if (i >= startIndex)                    print.addPage(page);            }        }    }[/code]

I got an error at below:

java.lang.ClassNotFoundException: com.alu.vital.vq.jasper.aggregation.AJPercentileAggregator        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)        at java.security.AccessController.doPrivileged(Native Method)        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)        at java.lang.Class.forName0(Native Method)        at java.lang.Class.forName(Class.java:270)        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:623)        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1610)        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1515)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:499)        at net.sf.jasperreports.engine.fill.JRTemplatePrintText.readObject(JRTemplatePrintText.java:901)        at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1891)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)        at java.util.ArrayList.readObject(ArrayList.java:733)        at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1891)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1913)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)        at java.util.ArrayList.readObject(ArrayList.java:733)        at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1891)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1913)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)        at java.util.ArrayList.readObject(ArrayList.java:733)        at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1891)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1913)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)        at java.util.ArrayList.readObject(ArrayList.java:733)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1891)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)        at net.sf.jasperreports.engine.base.ElementsBlock.readObject(VirtualizableElementList.java:567)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1891)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1989)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1913)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)        at net.sf.jasperreports.engine.base.JRVirtualPrintPage.readObject(JRVirtualPrintPage.java:241)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1891)        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1796)        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)        at com.alu.vital.vq.jasper.reportserver.AJPersistenceManager.readPages(AJPersistenceManager.java:333)[/code]

The "com.alu.vital.vq.jasper.aggregation.AJPercentileAggregator" class is class which i defined to perform percentile calculation. It was compiled when build report.

Why do i use JRVirtualPrintPage object to write into OutputStream and when read from InputStream, i also cast object to JRVirtualPrintPage type, why does this exception occur?

Please help me explain more details this. And how can i fix it? I think it relave to new Virtualize mechanism becaue this issue only occurs when i upgrade Jasper from 3.7.4 to 5.0.1

Thanks,

jMikel

  • 1 month later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Are you trying to read in pages that were written by older JRS, There might be two version of the same classes as a result of upgrade. I suspect that is the case. If so please clear everything and start from writing again. 

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...