0

我正在使用 Android 2.1 API。我通过 ksoap 协议从网上下载数据。结果就是这个异常org.ksoap2.serialization.SoapPrimitive,不明白为什么。

用debugging,for第一轮运行正常,第二轮就挂了education 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);
}
4

2 回答 2

0

错误消息听起来像您在下一行中的第二个属性不是 SoapObject 而是 Soap 原语,它在运行时会破坏它,因为您正在对它进行类型转换。

re = (SoapObject) ((SoapObject) envelope.getResponse()).getProperty(i);
于 2012-07-02T16:26:36.003 回答
0

只需转换为 SoapPrimitive 而不是 SoapObject。我也不知道为什么,但如果你看到代码,它可能是合乎逻辑的。

SoapPrimitive re = (SoapPrimitive)  envelope.getResponse().getProperty(i) ;
于 2012-12-29T21:55:32.233 回答