title: Android OS on network main thread exception
body: <p>I am working on an android application which connect with an asp.net web service.. for that when I tested the application is showing response </p>
  
  <blockquote>
    <p>Android OS on network main thread exception".</p>
  </blockquote>
  
  <p>My Code</p>
  
  <pre><code>class GetDetails extends AsyncTask&lt;String, String, String&gt;
  {
    @Override
    protected void onPreExecute() {
      super.onPreExecute();
      pDialog = new ProgressDialog(MainActivity.this);
      pDialog.setMessage("Loading the result... Please wait...");
      pDialog.setIndeterminate(false);
      pDialog.setCancelable(true);
      pDialog.show();
    }
  
    @Override
    protected String doInBackground(String... args)
    {
       try
       {
         runOnUiThread(new Runnable() {  
           @Override
           public void run() 
           {
             TextView webserviceResponse = (TextView) findViewById(R.id.textView1);
             webserviceResponse.setText("Requesting to server .....");
  
             //Create Webservice class object
             WebserviceCall com = new WebserviceCall(); 
  
             // Initialize variables
             String weight   = "18000";
             String fromUnit = "Grams";
             String toUnit   = "Kilograms";
  
             //Call Webservice class method and pass values and get response
             String aResponse = com.getConvertedWeight("ConvertWeight", weight, fromUnit, toUnit);   
  
             //Alert message to show webservice response
             Toast.makeText(getApplicationContext(), weight+" Gram= "+aResponse+" Kilograms", 
             Toast.LENGTH_LONG).show();
  
             Log.i("AndroidExampleOutput", "----"+aResponse);
  
             webserviceResponse.setText("Response : "+aResponse);
           }
         }
         );
       }
  
       finally  {
       }
       return null;
     }
  }
  
  
  protected void onPostExecute(String file_url) {
    // dismiss the dialog once got all details
    pDialog.dismiss();
  }
  
  }
  </code></pre>