我正在处理一个有问题的报告,当客户端JRE与服务器的JRE不同时,它总是抛出相同的异常。这是一个RMI应用程序,只有此报告才会出现异常。
这是一个简单的报告,但它有一个条形码组件,我使用了iReport 5.0.1(Barbecue和Barcode4j)提供的2个实现,并且都抛出了相同的异常:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.InvalidClassException: javax.swing.JComponent;
local class incompatible:
stream classdesc serialVersionUID = -2790168081368361182,
local class serialVersionUID = 5670834184508236790
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:191)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at $Proxy17.geraRelatorio(Unknown Source)
at base.gui.reports.ReportsPrinter.showReport(ReportsPrinter.java:151)
at base.gui.reports.ReportsPrinter.showReport(ReportsPrinter.java:139)
at jacad.gui.cadastros.curso.FrameCadastroPeriodoLetivo$30.executaAtividade(FrameCadastroPeriodoLetivo.java:1499)
at jdaap.gui.components.loader.Loader$1.doInBackground(Loader.java:70)
at jdaap.gui.components.loader.Loader$1.doInBackground(Loader.java:1)
at javax.swing.SwingWorker$1.call(SwingWorker.java:296)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at javax.swing.SwingWorker.run(SwingWorker.java:335)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.InvalidClassException: javax.swing.JComponent;
local class incompatible:
stream classdesc serialVersionUID = -2790168081368361182,
ocal class serialVersionUID = 5670834184508236790
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:604)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
我不知道现在做了什么,我已尽力解决这个问题,我不相信这个错误是由Java代码引起的,因为这个应用程序有+ - 300个报告,只有这个有一个条码。以下是RMI调用此报告的Java代码示例:
public JasperPrint executeReport(String reportFile, Map parameters) throws GenericException {
FileInputStream is = (FileInputStream) getReportFile(reportFile);
Connection conn = getConnection();
JasperPrint print = null;
try {
parameters.put("P_REPORTS_PATH", Application.getInstance().getReportsPath());
parameters.put(JRParameter.REPORT_LOCALE, new Locale("pt", "BR"));
print = JasperFillManager.fillReport(Application.getInstance().getReportsPath() + reportFile, parameters, conn);
} catch (JRException e1) {
e1.printStackTrace();
throw new GenericException(e1);
}
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return print;
}
客户方:
public static void view(final JasperPrint print) throws GenericException {
if (print == null) {
throw new GenericException("Nenhuma visualização do relatório foi informada.");
}
new SwingWorker() {
@Override
protected Void doInBackground() throws Exception {
JFrame viewer = new JFrame("Visualização do Relatório"); //$NON-NLS-1$
viewer.setPreferredSize(new Dimension(800, 600));
viewer.setLocationRelativeTo(null);
JasperViewer jrViewer = new JasperViewer(print, true);
viewer.getContentPane().add(jrViewer.getContentPane());
new FrameConfig(viewer);
return null;
}
}.execute();
}
public void showReport(String reportFile, Map parameters) throws GenericException {
if (reportFile == null)
throw new GenericException("Report file não pode ser nulo.");
ReportsManager rm;
try {
rm = (ReportsManager) FacadeFactoryLocal.newInstance(ReportsManager.class);
JasperPrint jasperPrint = rm.geraRelatorio(reportFile, parameters);
view(jasperPrint);
} catch (RemoteException e1) {
e1.printStackTrace();
throw new GenericException("Erro ao acessar o servidor para gerar o relatório.", e1.getStackTrace());
}
}
有人有解决方案吗?
提前致谢。
答案 0 :(得分:0)
不要序列化Swing组件。在每个人的Javadoc头上都有一个警告。序列化基础模型。