title: Code not working in onPostExecute function
body: <p>Having problem with the <code>onPostExecute</code> function. it did not call the function since nothing can be print out even with only <code>setText("Something")</code> function is called. Please help.... </p>
  
  <pre><code>public class Update extends Activity {
  
      JSONArray jArray = null;
      String result = null;
      StringBuilder sb = null;
      InputStream is = null;
      String ct_name;
      LinearLayout l;
      String responseString;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_update);
          Toast.makeText(getBaseContext(), "Done layout", Toast.LENGTH_LONG)
                  .show();
  
          new LongOperation().execute();
      }
  
      class LongOperation extends AsyncTask&lt;String, String, String&gt; {
          @Override
          protected String doInBackground(String... params) {
  
              // http post
  
              HttpClient httpclient = new DefaultHttpClient();
  
              // Why to use 10.0.2.2
              HttpPost httppost = new HttpPost(
                      "http://10.0.2.2/moodle/myFile.php");
              try {
                  ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  HttpResponse response = httpclient.execute(httppost);
                  response.getStatusLine().getStatusCode();
                  HttpEntity getResponseEntity = response.getEntity();
                  responseString = EntityUtils.toString(getResponseEntity);
  
              } catch (ClientProtocolException e) {
                  // TODO Auto-generated catch block
              } catch (IOException e) {
                  // TODO Auto-generated catch block
              }
              return responseString;
          }
  
          protected void onPostExecute(String resultStr) {
              try {
                  JSONObject json = new JSONObject(responseString);
                  JSONArray jArray = json.getJSONArray("result");
                  l = (LinearLayout) findViewById(R.id.container);
                  for (int i = 0; i &lt; jArray.length(); i++) {
                      JSONObject json_data = jArray.getJSONObject(i);
                      ct_name = json_data.getString("name");
                  }
                  TextView txt = (TextView) findViewById(R.id.txt_1);
                  txt.setText("Executed");
                  Toast.makeText(getBaseContext(), "this is post",
                          Toast.LENGTH_LONG).show();
  
                  Toast.makeText(getBaseContext(), ct_name, Toast.LENGTH_LONG)
                          .show();
                  TextView textView = new TextView(null);
                  textView.setText(ct_name
                          + " is out, please attempt it as soon as possible"
                          + "\n");
                  l.addView(textView);
  
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
      }
  
  }
  </code></pre>
  
  <p>This is the working code before the async task.</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  JSONArray jArray = null;
  String result = null;
  StringBuilder sb = null;
  InputStream is = null;
  String ct_name;
  LinearLayout l;
  @Override
  protected void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
  //http post
  try{
       HttpClient httpclient = new DefaultHttpClient();
  
       //Why to use 10.0.2.2
       HttpPost httppost = new HttpPost("http://10.0.2.2/moodle/myFile.php");
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
       HttpResponse response = httpclient.execute(httppost);
       HttpEntity entity = response.getEntity();
       is = entity.getContent();
       }catch(Exception e){
           Log.e("log_tag", "Error in http connection"+e.toString());
      }
  //convert response to string 
  try{
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
         sb = new StringBuilder();
         sb.append(reader.readLine() + "\n");
  
         String line="0";
         while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
          }
          is.close();
          result=sb.toString();
          }catch(Exception e){
                Log.e("log_tag", "Error converting result "+e.toString());
          }
  
  
  
  try{
        jArray = new JSONArray(result);
        JSONObject json_data=null;
  
          l = (LinearLayout) findViewById(R.id.container);
        for(int i=0;i&lt;jArray.length();i++){
               json_data = jArray.getJSONObject(i);
               ct_name=json_data.getString("name");//here "Name" is the column name in database
               Toast.makeText(getBaseContext(), ct_name,
                         Toast.LENGTH_LONG).show();
               TextView textView = new TextView(this);
               textView.setText(ct_name + " is out, please attempt it as soon as possible"+ "\n");
               l.addView(textView);
           }
  
  }
        catch(JSONException e1){
         Toast.makeText(getBaseContext(), "No Data Found" ,Toast.LENGTH_LONG).show();
        } catch (ParseException e1) {
     e1.printStackTrace();
   }
  
  
  }
  }
  </code></pre>