天天看点

开发安全卫士中遇到的问题

异常一:

Can‘t create handler inside thread that has not called Looper.prepare()

这个异常是因为非主线程中默认没有创建对象。

所以就要看看该方法所在的线程是不是主线程

一看。真的不是。于是取消new Thread().start();搞定。

问题1:

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

pd.setTitle("下载中");

pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

pd.show();

//File file=DownFile.Down(str, pd);刚才这段代码不在线程内。所以ProgressDialog不显示。

原因是不在子线程,在主线程。阻塞了UI刷新。

new Thread(new Runnable() {

public void run() {

String str=loginBean.getUrl();

File file=DownFile.Down(str, pd);

if(file!=null){

pd.dismiss();

}

}).start();

});

继续阅读