在我的應用程序我想通過double value
到web service
使用ksoap
但我得到NPE
。在代碼「exit_distance」是double值。任何機構可以找到的錯誤,並寄樣品例如android-如何通過雙倍的價值服務使用ksoap
代碼在這裏
//valus required for test
RB_Constant.RB_Webservice_URL = ?
RB_Constant.RB_Webservice_Namespace = ?
public String getExitsRestaurants() throws SoapFault
{
String data = "";
String serviceUrl = RB_Constant.RB_Webservice_URL;
String serviceNamespace = RB_Constant.RB_Webservice_Namespace;
String soapAction = "http://www.roadbrake.com/GetExitDetailsExtn";
String type_of_soap = "GetExitDetailsExtn";
try
{
SoapObject Request = new SoapObject(serviceNamespace, type_of_soap);
PropertyInfo HighwayIdObj = new PropertyInfo();
HighwayIdObj.name = "HighwayId";
HighwayIdObj.type = PropertyInfo.INTEGER_CLASS;
Request.addProperty("ExitNo", 7);
Request.addProperty(HighwayIdObj, highwayid);
Request.addProperty("HighwayName", 95);
Request.addProperty("exit_distance", 1.2);
System.out.println("Request Value->"+Request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
MarshalDouble md = new MarshalDouble();
md.register(envelope);
envelope.setOutputSoapObject(Request);
try
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(serviceUrl);
androidHttpTransport.call(soapAction, envelope);
}
catch(Exception e)
{
System.out.println("Webservice calling error ->"+e.toString());
}
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
data = response.toString();
System.out.println("web service response->"+response.toString());
}
catch(Exception e)
{
System.out.println("Soap Method Error ->"+e.toString());
}
return data;
}
public class MarshalDouble implements Marshal
{
@Override
public Object readInstance(XmlPullParser parser, String namespace, String name,
PropertyInfo expected) throws IOException, XmlPullParserException {
return Double.parseDouble(parser.nextText());
}
public void register(SoapSerializationEnvelope cm) {
cm.addMapping(cm.xsd, exit_distance, Double.class, this);
}
@Override
public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
writer.text(obj.toString());
}
}