Can't create handler inside thread that has not called Looper.prepare()
在android開發中,遇到這個問題:
問題原因:
在android的多線程開發中,比如asyncTask,在其doInBackground()方法,調用了更新UI的方法。
解決辦法:
把更新UI的操作,放到消息處理器中處理;在doInBackground()方法中發送更新消息:
Can't create handler inside thread that has not called Looper.prepare()
問題原因:
在android的多線程開發中,比如asyncTask,在其doInBackground()方法,調用了更新UI的方法。
解決辦法:
把更新UI的操作,放到消息處理器中處理;在doInBackground()方法中發送更新消息:
Handler updateDate = new Handler(){
@Override
public void handleMessage(Message msg) {
switch(msg.what){
case LOADING_FINISHED:
listView.setAdapter(gameAdapter);
break;
}
}
};
@Override
public void handleMessage(Message msg) {
switch(msg.what){
case LOADING_FINISHED:
listView.setAdapter(gameAdapter);
break;
}
}
};
posted on 2011-08-31 11:28 小一敗涂地 閱讀(12060) 評論(0) 編輯 收藏 所屬分類: android+移動開發 、錯誤集