Resource IDs cannot be used in a switch statement in Android library modules.

在組件化開發中,當我們使用switch來進行判斷操作時,會報這個錯誤,原因是R.id.XXX這類資源id在主application中是final,是常量,而在library中,是沒有final的。這裏盜個圖:

所以我們需要將switch轉變爲if else,直接選中switch,alt+enter,選擇replace switch with if .

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章