0

サーバ:

Registry registry = LocateRegistry.createRegistry(1099);

InventoryInterface Inventory = new Inventory(registry);

registry.bind("Inventory", Inventory);

クライアント:

Registry registry = LocateRegistry.getRegistry(1099);


InventoryInterface inventory = (InventoryInterface) registry.lookup("Inventory");


String product_id = inventory.newProduct();

ProductFacade product_1 = (ProductFacade) registry.lookup(product_id);

問題は、キャスト時に例外が発生することです。この場合、次の場所で発生します。ProductFacade product_1 = (ProductFacade) registry.lookup(product_id);

例外:

Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to rmi.ProductFacade
4

2 に答える 2

0

それはあなたがそれをどのようにバインドするかについてかもしれません。たとえば、ProductFacade が InventoryInterface を実装する場合、ProductFacade ではなく InventoryInterface としてキャストする必要がある場合があります。

于 2016-12-11T04:32:07.040 に答える