Java RMI Class Exception Exception

My project gets the Cast Exception class when the server starts, and then I tried to add the client using the incremental user interface, but when I tried it, it returned the Cast Exception class from the server connector class.

CustomerController interface

    public interface CustomerController {
    public boolean addCustomer(Customer customer)throws RemoteException,IOException,ClassNotFoundException;
}

ServerStart, Java

    public class ServerStart {
    public static void main(String[] args) {
          try {
            Registry registry=LocateRegistry.createRegistry(5050);
            System.out.println("Server is starting..");
            registry.rebind("Server", new CustomerControllerImpl());
        } catch (RemoteException ex) {
            Logger.getLogger(ServerStart.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

ServerConnector.java

    public class ServerConnector {

    private static ServerConnector serverConnector;
    private CustomerController customerController;

    private ServerConnector() throws NotBoundException, MalformedURLException, RemoteException {
        customerController = (CustomerController) Naming.lookup("rmi://localhost:5050/Server");
    }

    public static ServerConnector getServerConnector() throws NotBoundException, MalformedURLException, RemoteException {
        if (serverConnector == null) {
            serverConnector = new ServerConnector();
        }
        return serverConnector;
    }

    public CustomerController getCustomerController() {
        return customerController;
    }
}

The cast class exception occurs in the ServerConnector.java file in

customerController = (CustomerController) Naming.lookup("rmi://localhost:5050/Server");

CustomerControllerImpl.java

    public class CustomerControllerImpl extends UnicastRemoteObject implements CustomerController{

    private final CustomerFileAccess customerFileAccess = new CustomerFileAccess();

    public CustomerControllerImpl() throws RemoteException{

    }

    @Override
    public boolean addCustomer(Customer customer) throws RemoteException, IOException, ClassNotFoundException {
        return customerFileAccess.addCustomer(customer);
    }
}

here I attached the netbeans project , which can be downloaded from this link

Thanks!

+4
source share
1 answer

Looking through docs , I believe that this may be because your interface does not extend java.rmi.Remote.

+4

Source: https://habr.com/ru/post/1606411/


All Articles