In My application i want to pass the double value
to the web service
using ksoap
but i am getting the NPE
. In the code "exit_distance" is double value. can any body find the error in that and send the sample example
code here
//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());
}
}
you can simply set the type of the propertyInfo to be Double.class
Finally i solved the issue. The problem is in register() method of MarshalDouble class. The Following one is the Solution of that problem.
To be exact use it like this
the Marshal class
the implementation
The stack trace with the NPE should give you the line number where it happens. Just set a debug break point there and see for yourself what is null.