android - IllegalStateExcaption: Could not execute method of the activity -
In my application, I want to send a httpRequest on the button click. My button is the click of the event click button. My code is like this:
Public Zero click button (see V) {Toast. GetApplicationContext, "Inside Button Click", Toast. LNNHH_LOG). Show (); OrderNumber = (edit text) findViewById (R.id.order_no); DeliverTime = (edit text) findViewById (R.id.delivery_time); String id = orderNumber.getText (). ToString (); String tim = delete time.get text (). ToString (); Logs. I ("Button Click Value", "Inside Post" + Tim); String toopus = "url? Id =" + id + "& amp; time =" + tim; // TODO auto generated method stub log.i ("xxxxxxxx", "inside post"); Try {Http Client Client = getHttpClient (); HTTP post request = new HTTP post (toPass); Logs. I ("hpp request", "send reckoning" + papas); HttpResponse response = client.execute (request); } Hold (exception e) {Log.e ("problem in connection", e.toString ()); } Intent = new intent (getBaseContext (), MyRestaurantActivity.class); StartActivity; } But even the first toast is not being displayed and the application suddenly stops. Please help me get rid of this problem.
You can not perform network related operations on the main Tooth.
Use asyncTask as the following: Class Call Network Operation Asset Task & lt; String, integer, string & gt; {@Override Protected void onPreExecute () {// TODO auto-created method stub super.onPreExecute (); Progress Diallog Progress = New Progression Dioboog (YourActivityname.this); Progress.setTitle ("Sent Mail"); progress.setMessage ("Please wait ..."); Progress.show (); } @ Override protected string doInBackground (string ... parameter) {try {http Client Client = getHttpClient (); HTTP post request = new HTTP post (toPass); Logs. I ("hpp request", "send reckoning" + papas); HttpResponse response = client.execute (request); } Hold (exception e) {Log.e ("problem in connection", e.toString ()); } Return tap; } @ Override Protected Zero on postexec (string result) {/ TODO auto-generated method stub super.onPostExecute (results); Progress.dismiss (); Intent = new intent (getBaseContext (), MyRestaurantActivity.class); StartActivity; }}
Comments
Post a Comment