i have problem small test project.
-> ask restfull webservice
public string callrestwebservice(){ string result=""; system.out.println(".....rest.........."); httpclient httpclient = new defaulthttpclient(); httpget request = new httpget(wsurl); responsehandler<string> handler = new basicresponsehandler(); try { result = httpclient.execute(request, handler); system.out.println("..result..."+result); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } httpclient.getconnectionmanager().shutdown(); return(result); } // end callwebservice()
no problems code. after adding sdkversion in androidmanifest.xml
uses-sdk android:minsdkversion="16" android:targetsdkversion="23"
the app has exception in line
result = httpclient.execute(request, handler); caused by: android.os.networkonmainthreadexception @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1145) @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385) @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) @ java.net.inetaddress.getallbyname(inetaddress.java:214) @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:137) @ org.apache.http.impl.conn.abstractpoolentry.open(abstractpoolentry.java:164) @ org.apache.http.impl.conn.abstractpooledconnadapter.open(abstractpooledconnadapter.java:119) @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:360) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:653) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:627) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:616) @ info.rori.androidlunchbox.mainactivity.callrestwebservice(mainactivity.java:57) @ info.rori.androidlunchbox.mainactivity.oncreate(mainactivity.java:27) @ android.app.activity.performcreate(activity.java:5231) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) @ android.app.activitythread.performlaunchactivity(activitythread.java:2148) ... 11 more
where ist problem?
regards macleod
check stackoverflow post. has exact solution problem
Comments
Post a Comment