zoukankan      html  css  js  c++  java
  • 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.
    
    
  • 相关阅读:
    微信小程序 数组索引 data-“”解释
    Aho-Corasick算法原理(图省事我直接粘贴PPT了)
    神奇的人生
    nginx-学习笔记9
    nginx-学习笔记8
    nginx-学习笔记7
    nginx-学习笔记6
    nginx-学习笔记5
    nginx-学习笔记4
    nginx-学习笔记2
  • 原文地址:https://www.cnblogs.com/ouysq/p/5505209.html
Copyright © 2011-2022 走看看