zoukankan      html  css  js  c++  java
  • 线程练习中出现的错误


    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

  • 相关阅读:
    提问回顾与个人总结
    软工结对作业
    软件工程第一次阅读作业
    软件工程第0次作业
    oo第四次博客总结
    第三次博客总结
    第二次博客作业
    OO第一次总结博客
    软工第二次作业
    软工第一次作业
  • 原文地址:https://www.cnblogs.com/hishark/p/7573006.html
Copyright © 2011-2022 走看看