【问题标题】:Error with cast in ZeroC ICEZeroC ICE 中的投射错误
【发布时间】:2014-11-15 12:37:13
【问题描述】:

我通过我的 ice 文件生成 ZeroC 类。上面有两个类:“Device”和 DeviceServer 类,它只是第一个类的数组。该数组是由 DevicePrx 形成的,但是当我想强制转换第一个类以构建数组时,就会出现问题。这是服务器的 Ice.Application:

 public class Server extends Ice.Application {
  public int run(String[] args) {
    shutdownOnInterrupt();

    Ice.ObjectAdapter oa = communicator().createObjectAdapter("Servidor");
    Ice.ObjectPrx prx1 = oa.add(new DeviceI("descripción", DeviceStatus.DEVICEON), Ice.Util.stringToIdentity("Device1"));
    Ice.ObjectPrx prx2 = oa.add(new DeviceI("descripción2", DeviceStatus.DEVICEON), Ice.Util.stringToIdentity("Device2")); 

    DevicePrx [] oprx = new DevicePrx[2];

    oprx[0] = (DevicePrxHelper) prx2;
    DeviceServerI ds = new DeviceServerI(oprx);

    System.out.println(communicator().proxyToString(prx1) + " \n"+communicator().proxyToString(prx2));
    oa.activate(); 

    communicator().waitForShutdown();

    return 0;
  }

该演员表不起作用。当我执行该类时,它显示此错误:

!! 15/11/14 11:58:37:119 服务器:错误:主要:未知异常: java.lang.ClassCastException:无法强制转换 Ice.ObjectPrxHelperBase 到 ITSUE.DevicePrxHelper 在 Server.run(Server.java:13) 在 Ice.Application.doMain(Application.java:214) 在 Ice.Application.main(Application.java:194) 在 Ice.Application.main(Application.java:71) 在 Server.main(Server.java:26)

问题是:如何转换设备对象来构建阵列?

ICE 文件:

module ITSUE {
   enum DeviceStatus {
     DEVICEON,
     DEVICEOFF
   };
  class Device {
         ["private"] string description;
         ["private"] DeviceStatus status;

        void setStatus(DeviceStatus ns);
        DeviceStatus getStatus();       

        string getDescription();

        void on();
        void off();
  };
  sequence<Device *> DeviceSeq;
  class DeviceServer {
     ["private"] DeviceSeq devices;
     DeviceSeq listDevices();
  };
};

非常感谢!

【问题讨论】:

    标签: java casting distributed ice


    【解决方案1】:

    我自己解决了我的问题。如果有人遇到同样的问题,您必须使用 XXXXPrxHelper 类中的 checkedCast 或 uncheckedCast 方法进行转换。就我而言:DevicePrxHelper.checkedCast()

    【讨论】:

      猜你喜欢
      • 2011-12-03
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 2011-02-11
      • 2020-08-08
      • 2010-10-25
      • 1970-01-01
      相关资源
      最近更新 更多