代码: new Thread() {
public void run() {
try {
Toast.makeText(context, checkBean.getMsg(), 1).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
public void run() {
try {
Toast.makeText(context, checkBean.getMsg(), 1).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
异常:java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
原因:Toast中用到了Handler,而子线程中并没有初始化Looper,就不能调用Handler的当前的Looper对象了。
解决办法: Looper.prepare();
Toast.makeText(context, checkBean.getMsg(), 1).show();
Looper.loop();
探究:Handler与Looper之间的关系