java.lang.Integer不能强制转换为[Ljava.lang.Object;

java.lang.Integer不能强制转换为[Ljava.lang.Object;,java,xml-rpc,Java,Xml Rpc,我目前正在使用XML-RPC检索数据,这是我所拥有的: Object[] params = new Object[]{param1, param2}; Object[] obj = new Object[]{}; try { obj = (Object[]) client.execute("method.name", params); } catch (XmlRpcException e) { // TODO Auto-generated catch block e.p

我目前正在使用XML-RPC检索数据,这是我所拥有的:

Object[] params = new Object[]{param1, param2};
Object[] obj = new Object[]{};

try {
    obj = (Object[]) client.execute("method.name", params);
} catch (XmlRpcException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} 

return obj;

问题是有时它会返回-1,我会得到这样的错误:java.lang.Integer不能转换为[Ljava.lang.Object;-我想知道是否有办法解决这个问题?

在转换之前,您必须检查返回值的类型

Object result = client.execute(...);
if (result instanceof Integer) {
  Integer intResult = (Integer) result;
  ... handle int result
}    
else if (result instanceof Object[]) {
  obj = (Object[]) result;
}
else {
  ... something else
}

我很想围绕这些RPC调用创建一个强类型API。不过,也许你已经在这么做了…

它看起来像
客户端的返回值。execute
实际上不是
对象[]
,而是
整数
。或者可能是