我通过我的 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 无法在 Ice 的 Server.run(Server.java:13)上转换为 ITSUE.DevicePrxHelper .Application.doMain(Application.java:214) 在 Ice.Application.main(Application.java:194) 在 Ice.Application.main(Application.java:71) 在 Server.main(Server.java:26)
问题是:如何转换设备对象来构建阵列?
冰文件:
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();
};
};
非常感谢!