今天遇到以下錯誤bug: html
android.view.WindowManager$BadTokenException: Unable to add window -- android
token null is not valid; is your activity running? spa
最後終於發現是PopupWindow組件的使用問題,若是你直接在Activity建立的方法中初始化,則會有此錯誤 .net
所以總結:PopupWindow必須在某個事件中顯示或者是開啓一個新線程去調用,不能直在oncreate方法中顯示一個PopupWindow,不然永遠會有以上錯誤 線程
參考文章: htm
http://cb269267.iteye.com/blog/1787779 blog
http://blog.csdn.net/fulinwsuafcie/article/details/17192683 token
http://blog.sina.com.cn/s/blog_4b93170a0100q1km.html
事件