Thread in Android ---> Unfortunately ThreadApp has Stopped
<p>I have one textview, which i can use to show countdown timer. I wanted to use Thread class which takes Runnable interface.</p>

<p>I wrote the following code for the same but it is gives run time error <strong>Unfortunately ThreadApp has Stopped</strong></p>

<pre><code>import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity implements Runnable
{

TextView tvTimer;
Thread timerThread;
int time=30;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tvTimer =(TextView)findViewById(R.id.textView1);
    timerThread= new Thread(this);
    timerThread.start();
}

@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;
}

@Override
public void run()
{
    try
    {
        Thread.sleep(1000);
        tvTimer.setText((String.valueOf(time)).toString());
        time--;
    }
    catch (InterruptedException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}
</code></pre>

<p>At the same time when i removed <strong>tvTimer.setText((String.valueOf(time)).toString());</strong> it works fine. Can anyone provide me the solution. I am new in android.</p>
