天天看點

開發安全衛士中遇到的問題

異常一:

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();

});

繼續閱讀