Unable to add window -- token null is not for an application

android.view.WindowManager$BadTokenException:Unable to add window -- token null is not for anapplication

分析:

問題在於newAlertDialog.Builder(Context),雖然這裏的參數是AlertDialog.Builder(Contextcontext)

但我們不能使用getApplicationContext()獲得的Context,而必須使用Activity的Context對象,因爲只有一個Activity才能添加一個窗體。  

解決方法:

將new AlertDialog.Builder(Contextcontext)中的參數用Activity的Context對象即可.

發佈了57 篇原創文章 · 獲贊 17 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章