title: Android: Setting view to visible in AsyncTask's PreExecute causing error
body: <p>I have a <code>ProgressBar</code> in my layout:</p>
  
  <pre><code>&lt;ProgressBar
                  android:id="@+id/loading_pb"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_centerHorizontal="true"
                  android:layout_centerVertical="true" /&gt;
  </code></pre>
  
  <p>I make it "GONE" in my <code>onCreate</code>,</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Intent intent=getIntent();
          intent_data=intent.getExtras().getString("shipid");
  
          setContentView(R.layout.activity_shipment_event_finding);
          //loading=(TextView)findViewById(R.id.loader_tv);
          loading=(ProgressBar)findViewById(R.id.loading_pb);
          shipid_tv=(TextView)findViewById(R.id.shipid_val_tv);
          data=(TableLayout)findViewById(R.id.events_tl);
          viewmap=(Button)findViewById(R.id.view_map_btn);
          context=this;
          loading.setVisibility(View.GONE);
          shipid_tv.setText(intent_data);
          new EventFindAsyncTask().execute();
      }
  </code></pre>
  
  <p>Now in my <code>AsyncTask</code>, I want to make it visible in preExecute and GONE again in postExecute, Here is my <code>AsyncTask</code></p>
  
  <pre><code>private class EventFindAsyncTask extends AsyncTask&lt;Void, Void, JSONObject&gt;{
  
  
          protected void onPreExecute(){
              //loading.setVisibility(View.VISIBLE);
          }
  
          protected JSONObject doInBackground(Void... params){
  
                      String s;
                      String keyval=intent_data;
                      String orgcode=MainActivity.un.getText().toString();
                      JSONObject jsonobj=null, shipmentcodesend=null;
                      try{
                              jsonobj=new JSONObject(--Some huge JSON--);
  
                      }
                      catch(JSONException je){
                          Log.e("ShipmentEventFindingActivity.EventFindAsyncTask","JSON error" , je);
                          //ErrorDialog displayerror=new ErrorDialog(je, context);
                          //displayerror.showDialog();
                      }
  
  
  
                      System.out.println("Made jsonobject");
                      System.out.println(jsonobj.toString());
                      Log.d("EventFindAsyncTask.doInBackground", "gonna post");
                      JSONConnectorPost connector1=new JSONConnectorPost(jsonobj, getString(R.string.PIDsearch_url), MainActivity.cookieStore.getCookies());
                      JSONObject result=connector1.connectClient();
                      Log.d("EventFindAsyncTask.doInBackground", "Done post");
                      s=result.toString();
                      int responsecode=connector1.getResponsecode();
  
                      try{
                          String cacheID=result.getString("cacheId");
                          shipmentcodesend=new JSONObject(---Another huge JSON---);
                      }
                      catch(JSONException je){
                          Log.e("ShipmentEventFindingActivity.EventFindAsyncTask","JSON error" , je);
                          //ErrorDialog displayerror=new ErrorDialog(je, context);
                          //displayerror.showDialog();
                      }
  
                      System.out.println("Made shipmentcodesend");
                      System.out.println(shipmentcodesend.toString());
  
                      JSONConnectorPost connector2=new JSONConnectorPost(shipmentcodesend, getString(R.string.PIDsearch_url),MainActivity.cookieStore.getCookies());
                      shipmentcodes=connector2.connectClient();
  
                      return result;
          }
  
          protected void onPostExecute(JSONObject result){
  
              loading.setVisibility(View.GONE);
  
  .
  .
  .
  .
  .
  .
  Lot of other stuff
  .
  .
  .
  
          }
  </code></pre>
  
  <p>Now as long as the  line <code>loading.setVisibility(View.VISIBLE);</code> is commented, everything works perfectly. But as soon as I uncomment it, The <code>ProgressBar</code> does display, but the <code>doInBackground</code> stops at this part of the code:</p>
  
  <pre><code>Log.d("EventFindAsyncTask.doInBackground", "gonna post");
                          JSONConnectorPost connector1=new JSONConnectorPost(jsonobj, getString(R.string.PIDsearch_url), MainActivity.cookieStore.getCookies());
                          JSONObject result=connector1.connectClient();
                          Log.d("EventFindAsyncTask.doInBackground", "Done post");
  </code></pre>
  
  <p>I get the "gonna post", but I dont get the "Done post", and the <code>ProgressBar</code> is forever loading. Note that the program works without the loading bar and I've used the JSONConnector classes in ~5 other places in my app where they are working perfectly. The problem arises only when the <code>ProgressBar</code> is made visible. Any solutions?</p>