android - Issue in httpost app stops -


so, have code here: doesn't work , app has stopped, issue is, before when tried @ home worked fine...now doesn't! don't know wrong here, please take , tell me? thanks..

public class mainactivity extends activity {      edittext msgtextfield;     button sendbutton;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          setcontentview(r.layout.activity_main);              //make message text field object             msgtextfield = (edittext) findviewbyid(r.id.msgtextfield);             //make button object             sendbutton = (button) findviewbyid(r.id.sendbutton);         }          public void send(view v)         {             //get message message box             string  msg = msgtextfield.gettext().tostring();              //check whether msg empty or not             if(msg.length()>0) {                 httpclient httpclient = new defaulthttpclient();                 httppost httppost = new httppost("http://192.168.10.28/app/app1.php");                  try {                     list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2);                        namevaluepairs.add(new basicnamevaluepair("id", "01"));                        namevaluepairs.add(new basicnamevaluepair("message", msg));                        httppost.setentity(new urlencodedformentity(namevaluepairs));                        httpclient.execute(httppost);                         msgtextfield.settext(""); //reset message text field                         toast.maketext(getbasecontext(),"sent",toast.length_short).show();                 } catch (clientprotocolexception e) {                     e.printstacktrace();                 } catch (ioexception e) {                     e.printstacktrace();                 }             } else {                 //display message if text field empty                 toast.maketext(getbasecontext(),"all fields required",toast.length_short).show();             }         }      } 

here have manifes.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.form"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />     <uses-permission android:name="android.permission.internet" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.form.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>  </manifest> 

you doing stuff musn't called ui thread. can create asynctask such operations. see this more infos.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -