android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -
i developing app testing asp.net webservice in android.for simple webservice adding 2 numbers used.where numbers passed parameters.the result in dialogue.the webserver works in local. when application runs following result exception.i provided internet permission in manifest.
java.net.unknownhostexception(unable resolve host “http://url.com/”: no address associated hostname)
my code given below
main activity
public static string rslt=""; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button b1=(button)findviewbyid(r.id.button1); final alertdialog ad=new alertdialog.builder(this).create(); b1.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub try { edittext ed1=(edittext)findviewbyid(r.id.edittext1); edittext ed2=(edittext)findviewbyid(r.id.edittext2); int a=integer.parseint(ed1.gettext().tostring()); int b=integer.parseint(ed2.gettext().tostring()); rslt="start"; caller c=new caller(); c.a=a; c.b=b; // c.ad=ad; c.join(); c.start(); while(rslt=="start") { try { thread.sleep(10); }catch(exception ex) { } } ad.settitle("result of add of "+a+" , "+b); ad.setmessage(rslt); }catch(exception ex) { ad.settitle("error!"); ad.setmessage(ex.tostring()); } ad.show(); } }); } }
caller.java
public class caller extends thread { public callsoap cs; public int a, b; public void run() { try { cs = new callsoap(); string resp = cs.call(a, b); mainactivity.rslt = resp; } catch (exception ex) { mainactivity.rslt = ex.tostring(); } } }
callsoap.java
public class callsoap { public final string soap_action = "http://tempuri.org/add"; public final string operation_name = "add"; public final string wsdl_target_namespace = "http://tempuri.org/"; public final string soap_address = "url"; public callsoap() { } public string call(int a,int b) { soapobject request = new soapobject(wsdl_target_namespace,operation_name); propertyinfo pi=new propertyinfo(); pi.setname("a"); pi.setvalue(a); pi.settype(integer.class); request.addproperty(pi); pi=new propertyinfo(); pi.setname("b"); pi.setvalue(b); pi.settype(integer.class); request.addproperty(pi); soapserializationenvelope envelope = new soapserializationenvelope( soapenvelope.ver11); envelope.dotnet = true; envelope.setoutputsoapobject(request); httptransportse httptransport = new httptransportse(soap_address); object response=null; try { httptransport.call(soap_action+operation_name, envelope); response = envelope.getresponse(); } catch (exception exception) { response=exception.tostring(); } return response.tostring(); }
please me.thanks in advance.
i think testing in emulator. since service in real server, prefer using real device. also, using emulator ok. emulator shows weird behavior real web services. try using different emulator, preferably newly created one.
Comments
Post a Comment