web services - Android: Webservice throws exception -
i following error when try call webservice android application following logcat
05-15 12:33:26.327: e/error :(339): error on ioexception() system.web.services.protocols.soapexception: server unable process request. ---> system.exception: object reference not set instance of object. 05-15 12:33:26.327: e/error :(339): @ webservice.setlocationforandroid(string latitude, string longitude, string suserid) 05-15 12:33:26.327: e/error :(339): --- end of inner exception stack trace --- 05-15 12:33:26.327: w/system.err(339): soapfault - faultcode: 'soap:server' faultstring: 'system.web.services.protocols.soapexception: server unable process request. ---> system.exception: object reference not set instance of object. 05-15 12:33:26.337: w/system.err(339): @ webservice.setlocationforandroid(string latitude, string longitude, string suserid) 05-15 12:33:26.337: w/system.err(339): --- end of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.node@43e9fac0 05-15 12:33:26.377: w/system.err(339): @ org.ksoap2.serialization.soapserializationenvelope.parsebody(soapserializationenvelope.java:141) 05-15 12:33:26.377: w/system.err(339): @ org.ksoap2.soapenvelope.parse(soapenvelope.java:140) 05-15 12:33:26.387: w/system.err(339): @ org.ksoap2.transport.transport.parseresponse(transport.java:100) 05-15 12:33:26.387: w/system.err(339): @ org.ksoap2.transport.httptransportse.call(httptransportse.java:214) 05-15 12:33:26.397: w/system.err(339): @ org.ksoap2.transport.httptransportse.call(httptransportse.java:96) 05-15 12:33:26.397: w/system.err(339): @ com.practice.locationtracking.locationservice.sendlocation(locationservice.java:144) 05-15 12:33:26.397: w/system.err(339): @ com.practice.locationtracking.locationservice.access$0(locationservice.java:114) 05-15 12:33:26.397: w/system.err(339): @ com.practice.locationtracking.locationservice$1.run(locationservice.java:101) 05-15 12:33:26.397: w/system.err(339): @ android.os.handler.handlecallback(handler.java:587) 05-15 12:33:26.407: w/system.err(339): @ android.os.handler.dispatchmessage(handler.java:92) 05-15 12:33:26.407: w/system.err(339): @ android.os.looper.loop(looper.java:123) 05-15 12:33:26.417: w/system.err(339): @ android.app.activitythread.main(activitythread.java:4627) 05-15 12:33:26.417: w/system.err(339): @ java.lang.reflect.method.invokenative(native method) 05-15 12:33:26.417: w/system.err(339): @ java.lang.reflect.method.invoke(method.java:521) 05-15 12:33:26.417: w/system.err(339): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 05-15 12:33:26.417: w/system.err(339): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 05-15 12:33:26.417: w/system.err(339): @ dalvik.system.nativestart.main(native method)
please me solve problem. problem, cant find it..
the code follows of service sends data webservice.
package com.practice.locationtracking; import java.io.ioexception; import java.net.socketexception; import org.ksoap2.soapenvelope; import org.ksoap2.serialization.propertyinfo; import org.ksoap2.serialization.soapobject; import org.ksoap2.serialization.soapprimitive; import org.ksoap2.serialization.soapserializationenvelope; import org.ksoap2.transport.httptransportse; import android.app.service; import android.content.intent; import android.content.sharedpreferences; import android.os.handler; import android.os.ibinder; import android.preference.preferencemanager; import android.util.log; import android.widget.toast; public class locationservice extends service { gpstracker gps; private handler handler = new handler(); string latitude="27.40", longitude="72.40"; string userid = ""; private static final string tag = "locationservice"; //used getting handler other class sending messages public static handler mmyservicehandler = null; //used keep track on android running status public static boolean misservicerunning = false; @override public ibinder onbind(intent arg0) { // todo auto-generated method stub return null; } @override public void oncreate() { final sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(this); userid = prefs.getstring("user_name", null); toast.maketext(getapplicationcontext(), "user name : " + userid, toast.length_short).show(); //toast.maketext(this, "location tracking service created",toast.length_short).show(); log.d(tag,"on create"); } @override public void onstart(intent intent, int startid) { toast.maketext(this, "location tracking service started",toast.length_short).show(); log.d(tag,"on start"); } @override public int onstartcommand(intent intent, int flags, int startid) { toast.maketext(this, "location tracking service started",toast.length_short).show(); //toast.maketext(getapplicationcontext(), "user name : " + userid, toast.length_short).show(); misservicerunning = true; handler.post(timedtask); return start_sticky; } @override public void ondestroy() { handler.removecallbacks(timedtask); toast.maketext(this, "location tracking service stopped", toast.length_short).show(); log.d(tag, "ondestroy"); misservicerunning = false; // make false, service destroyed. } private runnable timedtask = new runnable() { @override public void run() { gps = new gpstracker(locationservice.this); if(gps.cangetlocation()) { double lat = gps.getlatitude(); double lon = gps.getlongitude(); latitude = double.tostring(lat); longitude = double.tostring(lon); if(latitude.equalsignorecase("0.0") || longitude.equalsignorecase("0.0")) { toast.maketext(getapplicationcontext(), "can not location details device", toast.length_short).show(); // system.out.println("we here"); } else { boolean flag = sendlocation(latitude, longitude, userid); //boolean flag = true; toast.maketext(getapplicationcontext(), "your location - \nlatitude: " + latitude + "\nlongitude: " + longitude + "\n flag: " + flag, toast.length_short).show(); } } else { gps.showsettingsalert(); } handler.postdelayed(timedtask, 5000); } }; private boolean sendlocation(string latitude, string longitude, string username) { /* final string namespace = "http://tempuri.org/"; final string url = "http://10.0.2.2:25722/newlocationmap/service.asmx"; final string soap_action = "http://tempuri.org/setlocationforandroid"; final string method_name = "setlocationforandroid"; */ final string namespace = "http://www.enoxonline.in/"; final string url = "http://www.enoxonline.in/webservice.asmx"; final string soap_action = "http://tempuri.org/setlocationforandroid"; final string method_name = "setlocationforandroid"; boolean flag = false; soapobject request = new soapobject (namespace, method_name); propertyinfo pi = new propertyinfo(); pi.setname("latitude"); pi.setvalue(latitude); pi.settype(string.class); request.addproperty(pi); pi = new propertyinfo(); pi.setname("longitude"); pi.setvalue(longitude); pi.settype(string.class); request.addproperty(pi); pi = new propertyinfo(); pi.setname("userid"); pi.setvalue(username); pi.settype(string.class); request.addproperty(pi); // request.addproperty("latitude",latitude); // request.addproperty("longitude", longitude); // request.addproperty("suserid", username); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.dotnet=true; envelope.xsd = namespace; envelope.enc = "http://schemas.datacontract.org/2004/07/entity"; envelope.setoutputsoapobject(request); system.out.println(request); try { httptransportse androidhttptransport = new httptransportse(url); androidhttptransport.setxmlversiontag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); androidhttptransport.call(soap_action, envelope); soapprimitive response = (soapprimitive)envelope.getresponse(); //log.e("result: ", "" + response.tostring()); system.out.println(response.tostring()); if(response.tostring().equalsignorecase("true")) { flag=true; } else { flag=false; } } catch(socketexception ex) { log.e("error : " , "error on socketexception " + ex.getmessage()); ex.printstacktrace(); } catch(ioexception ex1) { log.e("error : " , "error on ioexception() " + ex1.getmessage()); ex1.printstacktrace(); } catch(exception e) { log.e("error : " , "error on ioexception() " + e.getmessage()); e.printstacktrace(); } return flag; } }
it seems there error in send method, can't see variable not initialized. there lot of messy things. think these 2 methods should work code:
private runnable timedtask = new runnable() { @override public void run() { gps = new gpstracker(locationservice.this); if(gps.cangetlocation()) { latitude = double.tostring(gps.getlatitude()); longitude = double.tostring(gps.getlongitude()); if(latitude.equalsignorecase("0.0") && longitude.equalsignorecase("0.0")) toast.maketext(getapplicationcontext(), "can not location details device", toast.length_short).show(); else { boolean flag = sendlocation(latitude, longitude, userid); toast.maketext(getapplicationcontext(), "your location - \nlatitude: " + latitude + "\nlongitude: " + longitude + "\n flag: " + flag, toast.length_short).show(); } } else { gps.showsettingsalert(); } handler.postdelayed(timedtask, 5000); } }; private boolean sendlocation(string latitude, string longitude, string username) { final string namespace = "http://www.enoxonline.in/"; final string url = "http://www.enoxonline.in/webservice.asmx"; final string soap_action = "http://tempuri.org/setlocationforandroid"; final string method_name = "setlocationforandroid"; try { soapobject request = new soapobject (namespace, method_name); request.addproperty("latitude", latitude); request.addproperty("longitude", longitude); request.addproperty("userid", username); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.dotnet=true; envelope.setoutputsoapobject(request); httptransportse androidhttptransport = new httptransportse(url); androidhttptransport.call(soap_action, envelope); return boolean.getboolean(envelope.getresponse().tostring()); } catch(exception e) { log.e(tag, "error : " e.tostring()); return false; } }
also sure namespace, action, url , method correct?
Comments
Post a Comment