Loading

调用android的getColor()方法出现 java.lang.NoSuchMethodError: android.content.res.Resources.getColor

1.java.lang.NoSuchMethodError: android.content.res.Resources.getDrawable/getColor
或者 java.lang.NoSuchMethodError:android.content.Context.getDrawable/geColor

 

原因:Context类的getDrawable(res)/geColor(res)方法和Resources的getDrawable(res,theme)/getColor(res.theme)都是API21才添加的,低版本系统无法找到该方法所以报异常。

 

解决办法:
使用Resources的getDrawable(res),但是该方法在API22已废弃。
使用ContextCompat.getDrawable(context,res)。

 原文链接:https://blog.csdn.net/qq_22256565/article/details/52133565

posted @ 2018-08-10 19:26  妖久  阅读(495)  评论(0编辑  收藏  举报