Note that there are some explanatory texts on larger screens.

plurals
  1. POSend Data to Wampserver Android
    text
    copied!<p>I made a project which must generate a page on entering message, but it is not working for a reason. I am posting the code below.</p> <p>activity_main.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="@string/hello_world" /&gt; &lt;EditText android:id="@+id/edit1" android:layout_margin="20dp" android:layout_marginTop="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:hint="Write a message" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;Button android:id="@+id/button1" android:layout_gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Enter" android:onClick="send" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>MainActivity.java</p> <pre><code>package com.example.postapp; import java.util.ArrayList; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { EditText edit1; Button button1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edit1 = (EditText) findViewById(R.id.edit1); button1 = (Button) findViewById(R.id.button1); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void send(View v) { String msg = edit1.getText().toString(); if(msg.length()&gt;0) { //Toast.makeText(getBaseContext(), "enter length", Toast.LENGTH_SHORT).show(); HttpClient httpc = new DefaultHttpClient(); HttpPost httpost = new HttpPost("http://localhost/demo/server_scripr.php"); //Toast.makeText(getBaseContext(), "enter length0", Toast.LENGTH_SHORT).show(); try { List&lt;BasicNameValuePair&gt; vp = new ArrayList&lt;BasicNameValuePair&gt;(); //vp.add(new BasicNameValuePair("id","01")); vp.add(new BasicNameValuePair("message",msg)); httpost.setEntity(new UrlEncodedFormEntity(vp)); httpc.execute(httpost); edit1.setText(""); Toast.makeText(getBaseContext(), "Sent", Toast.LENGTH_SHORT).show(); } catch(Exception e) { e.printStackTrace(); } } else { Toast.makeText(getBaseContext(), "Please enter the field", Toast.LENGTH_SHORT).show(); } } } </code></pre> <p>AndroidManifest.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.postapp" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /&gt; &lt;uses-permission android:name="android.permission.INTERNET"/&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.postapp.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Thanks, help me in finding the solution</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload