Java RMI Class 转换异常
Java RMI Class Cast Exception
我的项目在启动服务器时出现 class Cast Exception 然后我尝试使用添加客户 UI 添加客户但是当我尝试它时 returns a Class 来自服务器连接器的 Cast Exception class.
接口客户控制器
public interface CustomerController {
public boolean addCustomer(Customer customer)throws RemoteException,IOException,ClassNotFoundException;
}
服务器启动,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 强制转换异常发生在 ServerConnector.java 文件
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);
}
}
这里附上了netbeans project which can be download thourgh this link
谢谢!
看了docs,我相信可能是因为你的界面没有扩展java.rmi.Remote。
我的项目在启动服务器时出现 class Cast Exception 然后我尝试使用添加客户 UI 添加客户但是当我尝试它时 returns a Class 来自服务器连接器的 Cast Exception class.
接口客户控制器
public interface CustomerController {
public boolean addCustomer(Customer customer)throws RemoteException,IOException,ClassNotFoundException;
}
服务器启动,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 强制转换异常发生在 ServerConnector.java 文件
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);
}
}
这里附上了netbeans project which can be download thourgh this link
谢谢!
看了docs,我相信可能是因为你的界面没有扩展java.rmi.Remote。