尝试在Person
RMI服务器上保存ServerOperation
对象时遇到问题。程序给了我很多错误:
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:688)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:835)
at java.rmi/sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:283)
at java.rmi/sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:260)
at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
at java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:209)
at java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:161)
at com.sun.proxy.$Proxy6.saveUser(Unknown Source)
at mainMenu.mainMenuController.registerPerson(mainMenuController.java:93)
... 61 more
我已经尝试解决了很多次,但我无法解决。 我的代码如下: RMIInterface.java
public interface RMIInterface extends Remote {
public void saveUser(Person p) throws RemoteException;
public Person accessUser(String email, String password) throws RemoteException;
public ArrayList<Book> getAvailableBooks() throws RemoteException;
}
ServerOperation.java
public class ServerOperation extends UnicastRemoteObject implements RMIInterface {
private static final long serialVersionUID = 1L;
private ArrayList<Person> users;
Library library;
protected ServerOperation() throws RemoteException {
super();
users = new ArrayList<>();
try{
library = new Library();
} catch(MalformedURLException | NotBoundException e) {
e.printStackTrace();
}
}
@Override
public void saveUser(Person p) throws RemoteException {
System.out.println("name=" + p.getPersonName() + " : surname=" + p.getPersonSurname() + " : email=" + p.getPersonEmail() +
" : password=" + p.getPersonPassword() + " REGISTERED");
users.add(p);
}
mainMenuController.java
public class mainMenuController extends UnicastRemoteObject implements Initializable {
private static RMIInterface look_up;
public void registerPerson(ActionEvent e) throws IOException {
try {
look_up = (RMIInterface) Naming.lookup("//localhost/MyServer");
Person p = new Person(registerTabName.getText(), registerTabSurname.getText(),
registerTabEmail.getText(), registerTabPassword.getText());
look_up.saveUser(p); // saving user in database
}
public mainMenuController() throws MalformedURLException, RemoteException, NotBoundException {
}
Person.java
public class Person extends UnicastRemoteObject {
...
public Person(String personName, String personSurname, String personEmail, String personPassword) throws MalformedURLException, RemoteException, NotBoundException {
...
}