title: Change TextView from AsyncTask
body: <p>The code below is going to act as a Timer. I was testing out the AsynchTask, when my app simply doesn't load the XML view. My code should work, but the view is not opening up. I later did some testing and moves the TextView variable "display" around a little and eventually got the view to show up, but the start button press didn't work... Can anyone tell me how I could get the TextView to update and run properly? Thanks!</p>
  
  <p>THE ENTIRE LAYOUT IS NOT DISPLAYING....</p>
  
  <pre><code> public class MainActivity extends Activity {
  timer tim = new timer();
  boolean running = true;
  int milli = 0;
  int secs = 0;
  int mins = 0;
  int hours = 0;
  ArrayList&lt;Lap&gt; laps = new ArrayList&lt;Lap&gt;(); 
  TextView display = (TextView) findViewById(R.id.textView1); //whats going on?
  LinearLayout lapsView = (LinearLayout) findViewById(R.id.lapsView);
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      try{
      Button b1 = (Button) findViewById(R.id.start);
      b1.setOnClickListener(startTimer);
  
      Button b2 = (Button) findViewById(R.id.stop);
      b2.setOnClickListener(stopTimer);
      }
      catch(Exception e1){
  
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  private OnClickListener startTimer = new OnClickListener() {
      public void onClick(View v) {
          if(!running){
          startWatch();
          }
          else if(running){
              try{
              tim.execute(""); //start the task
              }
              catch(Exception e1){
                  Toast.makeText(MainActivity.this, "Error starting: "+e1, Toast.LENGTH_LONG).show();
              }
          }
      }
  };
  
  private OnClickListener stopTimer = new OnClickListener() {
      public void onClick(View v) {
          if(running){
          stopWatch();
          }
      }
  };
  
  
  public void startWatch(){
      running = true;
  }
  public void stopWatch(){
      running= false;
  }
  
   public class timer extends AsyncTask&lt;String, Void, String&gt; {
      ////NOT WORKING!!!!
      @Override               
  protected String doInBackground(String... params) {
      while(true){
          while(!running){
              ///Do Nothing...
          }
              while(milli &lt; 1000 &amp;&amp; running){
              running = true;
              milli++;
              try{                
                  Thread.sleep(1);                
              }
              catch(Exception e1){
                  System.out.println(e1);
              }
              if(milli == 1000){
                  milli = 0;
                  secs++;         
              }
              if(secs == 60){
                  secs = 0;
                  mins++;             
              }
              if(mins == 60){
                  hours++;
                  mins = 0;
              }
  
              display.setText(milli+":"+secs+":"+mins+":"+hours);
          }               
          }
      }   
      }
  
  
   }
  </code></pre>
  
  <p>Debug Errors....</p>
  
  <pre><code>  Thread [&lt;1&gt; main] (Suspended (exception RuntimeException))    
  &lt;VM does not provide monitor information&gt;   
  ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2053    
  ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2154 
  ActivityThread.access$700(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 146    
  ActivityThread$H.handleMessage(Message) line: 1260  
  ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
  Looper.loop() line: 137 
  ActivityThread.main(String[]) line: 4949    
  Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
  Method.invoke(Object, Object...) line: 511  
  ZygoteInit$MethodAndArgsCaller.run() line: 1043 
  ZygoteInit.main(String[]) line: 810 
  NativeStart.main(String[]) line: not available [native method]
  </code></pre>