【Android】Error: Expected resource of type styleable [ResourceType]

本文鏈接:【Android】Error: Expected resource of type styleable [ResourceType] - 祝福的博客 - 博客頻道 - CSDN.NET


錯誤提示

解決辦法

參考鏈接



錯誤提示:

Error: Expected resource of type styleable [ResourceType]

這個錯誤在編譯運行時候并不會出現(xiàn),但是當需要編譯打包的時候,就會爆出這個異常。

這個錯誤出現(xiàn)的位置位于自定義View中,代碼如下:

TypedArray ta = mContext.obtainStyledAttributes(attrs);

? ? ?booleanhasBottomLine = ta.getBoolean(0,false);

? ? ?booleanhasTopLine = ta.getBoolean(1,false);

點擊異常信息會定位到第三行,只有當 TypedArray 獲取第二個屬性以后數(shù)據(jù)時,才會出現(xiàn)此異常,ta.getBoolean(0, false) 這句則不會報錯,其實這應該是一個警告,所以才會在調(diào)試的時候正常編譯,但卻在編譯簽名包的時候失敗。


解決辦法

解決辦法就是在使用TypedArray的方法處,加上@SuppressWarnings("ResourceType"),這樣即可過濾該警告,可以正常通過簽名編譯。例如:

@SuppressWarnings("ResourceType")

publicvoidinitView() {? ?

? ? TypedArray ta = ?mContext.obtainStyledAttributes(attrs);

? ? booleanhasBottomLine = ta.getBoolean(0,false);

? ? booleanhasTopLine = ta.getBoolean(1,false);? ?

? ? ta.recycle();}


參考鏈接

http://stackoverflow.com/questions/26360954/obtainstyledattributes-annotated-with-styleableres-suppress-warnings

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容