首页 > 编程语言 > 详细

线程练习中出现的错误

时间:2017-09-22 09:42:37      阅读:197      评论:0      收藏:0      [点我收藏+]

public
class MainActivity extends Activity { //1.define member variable Button bt; TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //2.init init(); //3.listener bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new Thread() { public void run() { try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int i=0;i<10;i++) { tv.setText("After Update:"+i); } } }; } }); } private void init() { // TODO Auto-generated method stub bt=(Button)this.findViewById(R.id.bt); tv=(TextView)this.findViewById(R.id.tv); } @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; } }

1.自己写一遍线程的时候头脑非常简单,直接在子线程里tv.setText("After Update:"+i);

你怕是个猪哦^(* ̄(oo) ̄)^

主线程和子线程不进行交互你怎么会看得到哦

傻逼

 

2.Thread你不start怎么让人家运行呀 记得start

new Thread{
        //......
}.start();

 

3.

技术分享

运行之后字符串为啥这样

技术分享

记得是msg.obj !!

 

 

4.是handleMessage不是HandleMessage

 

线程练习中出现的错误

原文:http://www.cnblogs.com/hishark/p/7573006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!