0

我正在处理一份有问题的报告,当客户端 JRE 与服务器的不同时,它总是抛出相同的异常。这是一个 RMI 应用程序,仅此报告会出现异常。


报告

这是一个简单的报告,但是它有一个条形码组件,我使用了 iReport 5.0.1 提供的 2 个实现(Barbecue 和 Barcode4j)并且都抛出了相同的异常:

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());

    }

}

有人对此有解决方案吗?

提前致谢。

4

1 回答 1

0

不要序列化 ​​Swing 组件。他们每个人的 Javadoc 的开头都有一个警告。序列化底层模型。

于 2013-01-22T23:02:36.080 回答