Only the original thread that created a view hierarchy can touch its views.

来源:互联网 发布:程序员专用显示器 编辑:程序博客网 时间:2024/05/21 06:49

尴尬今天写的时候犯了个低级错误,就是在子线程更新了UI,如下,切记

class CatchTask extends TimerTask
{
public void run() 
{


if(p!=null)
{
p.destroy();
}
if(i<1)//控制值循环一次
{
handleBit();//获取用户输入的字节数
cmd.setBit(defaultBit);//设置
p=cmd.catchPackage();//抓取
}
else
{
MyApplication.message= MyApplication.mhandler.obtainMessage();
MyApplication.message.what=1;
MyApplication.mhandler.sendMessage(MyApplication.message);//告诉主线程,自动抓取完成


timerCatch.cancel();
if(p!=null)
{
p.destroy();
}

}


i++;

et.setText("OK");//令textview显示的字变化。这里就是错的根源,看起来很对,然而这就是忘记了不能再非UI进程更新的问题。
}


//
}

0 0
原创粉丝点击