0
private String s;
EditText numDisplay;
Button calculateNow;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    numDisplay= (EditText)findViewById(R.id.editText1);
    calculateNow = (Button)findViewById(R.id.button1);
    s=numDisplay.toString();    
    calculateNow.setOnClickListener(new View.OnClickListener() {
         @SuppressWarnings("deprecation")
        public void onClick(View v) {
             // Perform action on click
             HttpClient httpclient = new DefaultHttpClient();
             HttpPost httppost = new HttpPost("http://primecalculation.appspot.com/");
             try {
                // Add your data
                @SuppressWarnings("deprecation")
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                nameValuePairs.add(new BasicNameValuePair("value", s));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block

            } }
     } );}}

I wrote the above code to post a number taken from user and want that entered number to be posted on server.

But I run program I find error after pressing button "Unfortunately stopped working".

Any help appreciated.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437

0 Answers0