zoukankan      html  css  js  c++  java
  • Android 报错:can't create handler inside thread that has not called looper.prepare() toast

    错误原因:在线程中更新UI!

    不要在子线程中更新UI!不要在子线程中更新UI!不要在子线程中更新UI!  重要的事情说三遍!!!

    错误代码如下:

    public class SendThread implements Runnable{
    
            @Override
            public void run() {
                // TODO Auto-generated method stub
                try{
    
                    sock.getOutputStream().write(new SendOver(P[6],P[7],P[8],P[9]).getbuf());  
                    Toast.makeText(getApplicationContext(), "I am sending", Toast.LENGTH_SHORT).show();  //此句应该删掉
                    sock.close(); 
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            
        }

    应该要把Toast 这个函数放在Handler中解决。

  • 相关阅读:
    html常用属性手记
    html常用标签手记
    linux安装与命令大全
    14.ref参数
    13.out参数
    10.结构
    9.枚举
    8.常量
    6.使用Convert进行类型转换
    5.C#中的转义符和@符号
  • 原文地址:https://www.cnblogs.com/lws520/p/6434447.html
Copyright © 2011-2022 走看看