我的应用程序基于几个 jar 文件:login.jar,mainform.jar,reportview.jar。
登录jar调用mainform.jar,它同样会调用report view.jar。
所以在reportview类中我有一个用 JasperViewer 显示报告的方法:
reportSource = Reportpath + getReportname() + ".jasper";
HashMap para = new HashMap();
para.put(getReport_param1(), getParam1());
para.put(getReport_param2(), getParam2());
para.put(getReport_param3(), getParam3());
para.put(getReport_param4(), getParam4());
para.put(getReport_param5(), getParam5());
JasperPrint jp = JasperFillManager.fillReport(reportSource, para, con);
JasperViewer.viewReport(jp, false);
因此,单个项目100%正确运行并查看报告。
但是当我将这个类导入到mainform并调用reportview方法时,它没有运行。我用了 JasperReports 库的 jasperreports-3.1.4.jar 文件。通过主要方法调用报告模块时,它工作正常 但是当从不同的jar调用它时会出现这个错误。
java.lang.ClassCastException:无法将net.sf.jasperreports.engine.base.JRBaseTextField的实例分配给net.sf.jasperreports.engine.JRBoxContainer类型的字段net.sf.jasperreports.engine.base.JRBaseLineBox.boxContainer在net.sf.jasperreports.engine.base.JRBaseLineBox的例子中 at java.io.ObjectStreamClass $ FieldReflector.setObjFieldValues(ObjectStreamClass.java:2032) at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1212) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1953) 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 java.util.ArrayList.readObject(ArrayList.java:593) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) 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.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:85) at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:244) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:316) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:399) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1300) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:631) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:228) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:730) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:632) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234) 在reportmodule.Reportmodule.getReport(Reportmodule.java:329) 在Login.Login $ 7.run(Login.java:344)
请帮我解决这个问题。
答案 0 :(得分:0)
最后我发现了错误。因为其他一些项目(mainform.jar)是导入旧版本的jasper库(1.2)。从mainform中删除该库解决了我的问题。