My project gets class Cast Exception when I started server and then I tried to add customer using add customer UI but when I tried for it it returns a Class Cast Exception from the server connector class.
interface CustomerController
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;
}
}
Class cast Exception occurs at ServerConnector.java file at
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 download thourgh this link
Thank you!.
浏览文档 ,我相信这可能是因为您的界面没有扩展java.rmi.Remote。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.