1

在 RMI 服务器中:

 ctx = new InitialContext();           
 Account rs = new RemoteServer();
 rmiPathForObject="rmi://"+IP+":"+port+"/loginuser";
 ctx.bind(rmiPathForObject, rs); 

客户:

Context ctx;
Account acc = null;
try {
    ctx = new InitialContext();

    Object o = ctx.lookup("rmi://localhost:2345/loginuser");
    acc = (Account) o;
} catch (NamingException ex) {
    Logger.getLogger(DTTMessenger.class.getName()).log(Level.SEVERE, null, ex);
}

当我将客户端连接到服务器时,会发生以下异常。为什么会抛出这个异常?我怎样才能解决这个问题?

Nov 27, 2012 11:23:09 AM dttmessenger.DTTMessenger btnLoginActionPerformed SEVERE: null
    javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
        java.lang.ClassNotFoundException: dttserver.Account (no security manager: RMI class loader disabled)]
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:118)
        at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:203)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at dttmessenger.DTTMessenger.btnLoginActionPerformed(DTTMessenger.java:141)
        at dttmessenger.DTTMessenger.access$000(DTTMessenger.java:22)
        at dttmessenger.DTTMessenger$1.actionPerformed(DTTMessenger.java:75)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
        at java.awt.Component.processMouseEvent(Component.java:6505)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6270)
        at java.awt.Container.processEvent(Container.java:2229)
        at java.awt.Component.dispatchEventImpl(Component.java:4861)
        at java.awt.Container.dispatchEventImpl(Container.java:2287)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
        at java.awt.Container.dispatchEventImpl(Container.java:2273)
        at java.awt.Window.dispatchEventImpl(Window.java:2719)
        at java.awt.Component.dispatchEvent(Component.java:4687)
4

1 回答 1

2

您需要将异常中命名的类部署到客户端。重复直到关闭。看起来好像您可能在不同的包中有两个 Account 类,这当然使它们有所不同。

于 2012-11-27T09:48:10.463 回答