可能是当有多个记录时,服务返回Vector<SoapObject>
,当只有记录时,它只返回SoapObject
。
您正在尝试转换SoapObject
为Vector<SoapObject>
,所以ClassCastException
.
这是服务实施的问题。但是,要在最后解决此问题,您应该首先获取envelope.getResponse()
as Object
,并在强制转换之前检查是否Object
为实例Vector<SoapObject>
或SoapObject
。
Vector<SoapObject> vectorOfSoapObject = null;
Object response = envelope.getResponse();
if( response instanceof Vector){
Vector<SoapObject> vectorOfSoapObject = (Vector<SoapObject>) response;
}else if(response instanceof SoapObject){
//cast single object
SoapObject soapObject = (SoapObject) response;
//initialize vector
vectorOfSoapObject = new Vector<SoapObject>();
//add single object to vector.
vectorOfSoapObject.add(soapObject);
}
这样你就不必更改你可能已经编写的其他代码,假设你总是会得到列表