I cannot post my required data to my PHP website using my android app -


This is my code as soon as my app crashes as a pressed send button

Public class MainActivity Enhances ActionBarActivity {

  Send Public Zero (see V) {// Message Box String msg msg msg msg: textField.getText () ToString (); // Check whether the message is empty or not (msg.length ()> 0) {HttpClient httpclient = New DefaultHttpClient (); Http post httppost = new HTTP post ("http://www.soshelp.site50.net/index.php"); {List & lt; NameValuePair & gt; NameValuePairs = New ArrayList & lt; NameValuePair & gt; (2); NameValuePairs.add (New BasicNameValuePair ("id", "01")); NameValuePairs.add (New BasicNameValuePair ("message", msg)); Httppost.setEntity (new UrlEncodedFormEntity (nameValuePairs)); Httpclient.execute (httppost); MsgTextField.setText (""); // Message Text Field Toast.makeText (getBaseContext (), "Sent", Toast .LENGTH_SHORT). Show (); } Hold (Client Protocol E) e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); }} Else {// display message if the text field is empty then. Make text (getBaseContext), "All fields are required", Toast. LNNGHHORT). Show (); }    

To execute correctly you must put your code in a separate thread, Correct for all server calls in Android:

  Send public zeros (see V) {thread thread = new thread () {@Override public void run () {// Get message from message Box String msg = msgTextField.getText (). ToString (); // Check whether the message is empty or not (msg.length ()> 0) {HttpClient httpclient = New DefaultHttpClient (); Http post httppost = new HTTP post ("http://www.soshelp.site50.net/index.php"); {List & lt; NameValuePair & gt; NameValuePairs = New ArrayList & lt; NameValuePair & gt; (2); NameValuePairs.add (New BasicNameValuePair ("id", "01")); NameValuePairs.add (New BasicNameValuePair ("message", msg)); Httppost.setEntity (new UrlEncodedFormEntity (nameValuePairs)); Httpclient.execute (httppost); MsgTextField.setText (""); // Message Text Field Toast.makeText (getBaseContext (), "Sent", Toast .LENGTH_SHORT). Show (); } Hold (Client Protocol E) e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); }} Else {// display message if the text field is empty then. Make text (getBaseContext), "All fields are required", Toast. LNNGHHORT). Show (); }}}; Thread.start (); }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -