java - httppost cause the app to crash -
i'm trying send post request php page through java in android studio
first tried httppost , app crashed after pressing key
then read have use new thread , did still
the app crashes
here code :
public void send () { final string name,phone,fb; edittext one,two,three; one=(edittext) findviewbyid(r.id.edittext); two=(edittext) findviewbyid(r.id.edittext2); three=(edittext) findviewbyid(r.id.edittext3); name=one.gettext().tostring(); phone=two.gettext().tostring(); fb=three.gettext().tostring(); thread t=new thread(new runnable() { @override public void run() { httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://test.com/test.php"); try { list <namevaluepair> namevaluepairs= new arraylist<namevaluepair>(2); namevaluepairs.add(new basicnamevaluepair("name",name)); namevaluepairs.add(new basicnamevaluepair("number",phone)); namevaluepairs.add(new basicnamevaluepair("fbname",fb)); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response= httpclient.execute(httppost); } catch (clientprotocolexception e) { // todo auto-generated catch block } catch (ioexception e) { // todo auto-generated catch block } } }); t.start(); }
make sure have permissions communicating internet set in manifest file. if not, throw securityexception , break app.
<uses-permission android:name="android.permission.internet" /> other that, can't see in log cause exception.
update
after checking code provided user problem coming fact onclick event supposed trigget send() method while unknowingly defining without required view v parameter.
the solution (to problem, doesn't mean make httppost work) simple add parameter definition of method:
public void send (view v) {
Comments
Post a Comment