Android开发Can't create handler inside thread that has not called Looper.prepare()

来源:互联网 发布:tor网络 原理 编辑:程序博客网 时间:2024/05/15 05:38
public void onResponse(final Response response) throws IOException {
        
Toast.makeText(MainActivity.this, "test.", Toast.LENGTH_SHORT).show();
    
}
在线程中加入Toast提示,出现如下error: 
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
修改后:
public void onResponse(final Response response) throws IOException {
        
        Looper.prepare();              
Toast.makeText(MainActivity.this, "d", Toast.LENGTH_SHORT).show();
   
        Looper.loop();
     
}
即可正常运行。

0 0
原创粉丝点击