0
         HttpClient Client = new DefaultHttpClient();

         String URL = "http://192.168.2.22:1099/Service1.svc/test";

         try
         {
            String setServerString = "";
            HttpGet httpget = new HttpGet(URL);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            setServerString = Client.execute(httpget, responseHandler);
            lblStatus.setText(setServerString);
         }
         catch(Exception ex)
         {
           lblStatus.setText("Fail!");
         }

when we call the url it returns a string and is set to lblStatus. This code is working fine in v2.3.* but not working in v4.0. i'm able to get the string in v2.3.* versions but not in v4.0.

Bobbake4
  • 24,509
  • 9
  • 59
  • 94
user223100
  • 43
  • 3

1 Answers1

0

Indeed you are getting the NetworkOnMainTreadException. This exception has been introduced with HoneyComb and it is raised when an attempt of run a network operation on the UI Thread is made.

If you want to overcame it you have to use an AsyncTask. Read the android painless threading guide

Blackbelt
  • 156,034
  • 29
  • 297
  • 305