问题
I have a server and client using Java RMI. If I use one client all is fine with the code below. But if I connect with a client and then a second one, it throws port already in use exception. That's fine, so I disconnect the connected client and then try to connect with the second client again. It gives me this:
java.rmi.NoSuchObjectException: no such object in table
Why is this?
//CONNECT
Registry registry = LocateRegistry.getRegistry(
Options.getRegistryIp(), Options.getRegistryPort());
server = (IServer) registry.lookup(Constants.MB_SERVER_NAME);
UnicastRemoteObject.exportObject(client, Options.getMyPort());
server.registerClient(client);
//DISCONNECT
server.removeClient(client, client.getUser());
UnicastRemoteObject.unexportObject(client, false);
回答1:
NoSuchObjectException means that the stub refers to a remote object which has been unexported, either explicitly or via GC. Are you getting this on the lookup(), or the registerClient(), or the removeClient()?
来源:https://stackoverflow.com/questions/4986272/java-rmi-nosuchobjectexception