java.lang.NoSuchMethodError:android.content.Context.getDrawable


今天在開發的時候,這個代碼在源碼中是可以看到的,但是在android 4.3手機上面會報錯,具體錯誤信息和代碼如下:
setBackgroundDrawable(context.getDrawable(R.drawable.coach_popou_window));
會報這個錯誤
java.lang.NoSuchMethodError:android.content.Context.getDrawable
查閱資料可以得到這個解釋:

 

改成這樣即可

setBackgroundDrawable(ContextCompat.getDrawable(context,R.drawable.coach_popou_window))
主要原因是因為是版本不對,如果是android 5.0以上的手機是支持的
Prior to android.os.Build.VERSION_CODES#JELLY_BEAN, this function would not correctly retrieve the final configuration density when the resource ID passed here is an alias to another Drawable resource. This means that if the density configuration of the alias resource is different than the actual resource, the density of the returned Drawable would be incorrect, resulting in bad scaling.
 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM