我正在使用Android 2.1 API。我通过网络,通过ksoap协议下载数据。结果是此异常org.ksoap2.serialization.SoapPrimitive
并且不明白原因。
通过调试,for
在第一轮正确运行,但第二次挂起教育re = (SoapObject) ((SoapObject) envelope.getResponse ()). getProperty (s)
,报告错误org.ksoap2.serialization.SoapPrimitive
。
以下是代码:
request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("dev", false);
request.addProperty("Cap", input_cap.getText().toString());
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE,Offerta.Offerta_CLASS.getSimpleName(),Offerta.Offerta_CLASS);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
int nOff = ((SoapObject) envelope.getResponse()).getPropertyCount();
SoapObject re;
for (int i = 0; i < nOff; i++) {
re = (SoapObject) ((SoapObject) envelope.getResponse()).getProperty(i);
img.setImageBitmap(getBitmap(Integer.parseInt(re.getProperty(0).toString())));
titolo.setText(re.getProperty(1).toString());
descrizioneTitolo.setText(re.getProperty(3).toString());
provincia.setText(getProvincia(Integer.parseInt(re.getProperty(13).toString())));
sintesi.setText(re.getProperty(2).toString());
contenitore_paese.addView(view);
}
答案 0 :(得分:0)
错误消息听起来像下一行中的第二个属性不是SoapObject而是Soap原语,它在运行时打破它,因为你是类型转换它。
re = (SoapObject) ((SoapObject) envelope.getResponse()).getProperty(i);
答案 1 :(得分:0)
只需转换为SoapPrimitive而不是SoapObject。我也不知道为什么,但是如果你看到代码,它可能是合乎逻辑的。
SoapPrimitive re = (SoapPrimitive) envelope.getResponse().getProperty(i) ;