我在asyncTask中发出了一个soap请求,但我得到了像
这样的奇怪错误04-18 13:51:25.070: E/AndroidRuntime(23482): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:658)
04-18 13:51:25.070: E/AndroidRuntime(23482): at com.mobilion.afad.RegisterDevice.getWebService(RegisterDevice.java:49)
04-18 13:51:25.070: E/AndroidRuntime(23482): at com.mobilion.afad.RegisterDevice.access$0(RegisterDevice.java:44)
04-18 13:51:25.070: E/AndroidRuntime(23482): at com.mobilion.afad.RegisterDevice$requestTask.doInBackground(RegisterDevice.java:109)
这些是我的方法
private boolean getWebService(String Method, SoapSerializationEnvelope SoapRequest)
{
HttpTransportSE httpTransport = new HttpTransportSE(SoapAddress);
try
{
httpTransport.call(Soapaction, SoapRequest);
//httpTransport.call(NameSpace + Method, SoapRequest);
return true;
}
catch (IOException e)
{
e.printStackTrace();
return false;
}
catch (XmlPullParserException e)
{
e.printStackTrace();
return false;
}
}
和
protected Boolean doInBackground(String... params)
{
SoapSerializationEnvelope envelope = null;
//Ayarlardan secimi enlemi boylamı al property olarak ekle
SoapObject request = new SoapObject(NameSpace, "InsertUser");
// if(Ayarlar.secim == 0){
request.addProperty("deviceId", mDeviceId);
request.addProperty("enlem","0");
request.addProperty("boylam", "0");
request.addProperty("depremMin", Ayarlar.mindeprem);
request.addProperty("depremMax", "10");
request.addProperty("mesafe", "0");
request.addProperty("statu", "1");
request.addProperty("deviceType","2");
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// }
/* else if(Ayarlar.secim ==1){
request.addProperty("deviceId", mDeviceId);
request.addProperty("enlem",Ayarlar.Latitude);
request.addProperty("boylam", Ayarlar.Longitude);
request.addProperty("depremMin", Ayarlar.mindeprem);
request.addProperty("depremMax", "10");
request.addProperty("mesafe", Ayarlar.maxmesafe);
request.addProperty("statu", "1");
request.addProperty("deviceType", "2");
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
} */
return getWebService("InsertUser", envelope);
}
答案 0 :(得分:0)
这是抛出异常的方法:
private void writeElement(XmlSerializer writer, Object element,
PropertyInfo type, Object marshal)
throws IOException {
if (marshal != null) {
((Marshal) marshal).writeInstance(writer, element);
} else if (element instanceof SoapObject) {
writeObjectBody(writer, (SoapObject) element);
} else if (element instanceof KvmSerializable) {
writeObjectBody(writer, (KvmSerializable) element);
} else if (element instanceof Vector) {
writeVectorBody(writer, (Vector) element, type.elementType);
} else {
throw new RuntimeException("Cannot serialize: " + element);
}
}
正如您所看到的,当被序列化的element
不是预期类型之一时,它会被抛出。根据您收到的消息判断,实际对象很可能是Float
或Double
或BigDecimal
实例。我会仔细查看您在请求属性中添加的值。
然而,有一些令人费解的事情。根据堆栈跟踪,writeElement
方法直接调用getWebService
方法。但是,根据源代码是不可能的。你...嗯...编辑堆栈跟踪?如果您希望人们为您提供准确的问题诊断,那就是一个不好的想法。