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.
    
    
  • 相关阅读:
    POJ2777
    链表
    模板
    poj 3468(线段树)
    用react编写一个hello world
    用express快速写一个hello world
    naturalWidth与naturalHeight
    div里面的图片垂直居中
    js将网址转为二维码并下载图片
    记一个视频播放器插件 video.js
  • 原文地址:https://www.cnblogs.com/ouysq/p/5505209.html
Copyright © 2011-2022 走看看