猿问

android 有关线程和Handler的问题,一起动线程APP就闪退!

//启动thread
try{
    this._socket.connect();
    Toast.makeText(this, "连接" + this._device.getName() + "成功!", 0).show();
    this.ReadThread.start();
}
catch (IOException localIOException4) {
    Toast.makeText(this, "接收数据失败!", 0).show();
    //return;
}

//这是Thread

Thread ReadThread = new Thread() {
   public void run() {

Message msg=new Message();

msg.obj="123";
msg.what=1;
handler.sendMessage(msg);

}

}

//这是Handler

private Handler handler =new Handler() {

   @Override
   public void handleMessage(Message msg) {
       if(msg.what==1){
           BTClient bt =new BTClient();
           bt.tv.setText("123");
          // bt.sv.scrollTo(0, bt.dis.getMeasuredHeight());
       }
   }
};

hitman
浏览 1756回答 1
1回答

hitman

Thread最后加上;
随时随地看视频慕课网APP

相关分类

Java
我要回答