title: Android thread.start() and runOnUiThread(thread);
body: <p>What's wrong with this code?  When I implement it like this, my app works properly.</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          textOut = (EditText) findViewById(R.id.textout);
          IPAddress = (EditText) findViewById(R.id.editTextIPAddress);
          Button buttonSend = (Button) findViewById(R.id.send);
          Button buttonSet = (Button) findViewById(R.id.set);
          textIn = (TextView) findViewById(R.id.textin);
          buttonSend.setOnClickListener(buttonSendOnClickListener);
          buttonSet.setOnClickListener(buttonSetOnClickListener);
  
  
          Thread myThread = new Thread()
          {
              public void run()
              {
                  runClient();
              }// end method run
          };// end myThread
      }// end method onCreate
  </code></pre>
  
  <p>but when I implement it this way.  It force closes:</p>
  
  <pre><code>Button.OnClickListener buttonSetOnClickListener = new Button.OnClickListener()
      {
  
          @Override
          public void onClick(View arg0)
          {
              myThread.start();
          }// end method onClick
      };
  Thread myThread = new Thread()
      {
          public void run()
          {
              runClient();
          }// end method run
      };// end myThread
  </code></pre>
  
  <p>I was able to try this but it changes the logic of the program:</p>
  
  <pre><code>Button.OnClickListener buttonSetOnClickListener = new Button.OnClickListener()
      {
  
          @Override
          public void onClick(View arg0)
          {
              runOnUiThread(myThread);
          }// end method onClick
      };
  
      Thread myThread = new Thread()
      {
          public void run()
          {
              runClient();
          }// end method run
      };// end myThread
  </code></pre>
  
  <p>The first code runs myThread once the onCreate() is called.  The problem is I want to run myThread once a button is pressed.  But doing this results to a force closed.  What causes this force close and what should I do to run a thread once a button is pressed?</p>