首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

想在窗体下做一个倒数计时器,请帮看看上面的代码如何一运行就Forced Closed

2012-11-16 
想在窗体上做一个倒数计时器,请帮看看下面的代码怎么一运行就Forced Closed ?想通过txtSec显示从60秒倒数

想在窗体上做一个倒数计时器,请帮看看下面的代码怎么一运行就Forced Closed ?
想通过txtSec显示从60秒倒数到0的效果,请问下面的代码有什么问题?

public class Activity2 extends Activity {
private int Sec;
private TextView txtSec;
private TextView txtview1;

  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity2);
   
  Sec=60;
  txtSec=(TextView) this.findViewById(R.id.txtSec);
 
  handler.post(updateThread);
  }
   
   
  Handler handler=new Handler();
   
  Runnable updateThread=new Runnable(){
  public void run(){
  Sec--;
  txtSec.setText(Sec);
  if (Sec>0){
  handler.postDelayed(updateThread, 1000);
  }else{
  handler.removeCallbacks(updateThread);
  }
  }
  };  
}

[解决办法]
看下logCat信息报什么错

热点排行