今天在开发的时候,这个代码在源码中是可以看到的,但是在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.
												

java.lang.NoSuchMethodError:android.content.Context.getDrawable的更多相关文章

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

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

  2. 关于java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground的解决办法

    今天用一个安卓4.0.4版本的手机测试手上的项目,发现logcat弹出这样一个提示“java.lang.NoSuchMethodError: android.widget.RelativeLayout ...

  3. java.lang.NoSuchMethodError: android.view.View.setBackground

    int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { ...

  4. 【Exception】 java.lang.NoSuchMethodError: android.app.AlertDialog$Builder.setOnDismissListener

    f(Build.VERSION.SDK_INT >10) builder =newAlertDialog.Builder(getActivity(), R.style.Theme.Sherloc ...

  5. 【bug】java.lang.NoSuchMethodError: android.widget.TextView.setBackground

    安卓的背景色设置需要根据SDK的版本来分情况考虑: if (Build.VERSION.SDK_INT >= 16) { textView.setBackground(null); } else ...

  6. android studio: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution o

    今天在运行部署项目时logcat弹出下列错误: -- ::-/? E/Zygote: v2 -- ::-/? I/libpersona: KNOX_SDCARD checking this -- :: ...

  7. Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet] 异常

    1. 异常描述 FATAL EXCEPTION: main Process: com.whereru.greengrass.goforit, PID: 13847 java.lang.RuntimeE ...

  8. Caused by: java.lang.NoSuchMethodException: &lt;init&gt; [class android.content.Context, interface android

     在写自己定义的view时,有时会报下面错误: Caused by: java.lang.NoSuchMethodException: <init> [class android.co ...

  9. java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.getEnvironment()Lorg/springframework/core/env/ConfigurableEnvironment;问题

    在springsecurity学习中,在加入spring有关的jar包后,出现java.lang.NoSuchMethodError: org.springframework.web.context. ...

随机推荐

  1. JAVA上传与下载

    java下载指定地址的文件 package com.test; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...

  2. html路径问题

     1.绝对路径     绝对路径是指文件在硬盘上真正存在的路径.例如"bg.jpg"这个图片是存放在硬盘的"E:\book\网页布局代码\第2章"目录下,那么 ...

  3. 遇到scan configurtation CDT builder等的错误

    可以直接propoerty中的builder中把这两项删除

  4. Lniux下安装mysql----编译版

    ####安装mysql-5.7.10rpm -e --nodeps mysqlrpm -e mysqlclient10useradd -g mysql -s /sbin/nologininstall_ ...

  5. jQuery UI 日期选择器(Datepicker)

    设置JqueryUI DatePicker默认语言为中文 <!doctype html><html lang="en"> <head> < ...

  6. UNITY VR 视频/图片 开发心得(一)

    现在的VR似乎没有之前那么火热了,于是乎我居然开始了VR征程... 说起VR,对于没有接受过相关知识的人来说可能看起来比较高大上,但是VR的原理却没有想象中那么复杂.总的来说,VR之所以能够产生立体感 ...

  7. Angular--ui-router的使用

    先引用Angular然后引用ui-router 路由清单:我们依赖的ui.router中提供了一个服务$state,此时可以用config来配置这个服务.用$stateProvider的state方法 ...

  8. 深入理解javascript异步编程障眼法&&h5 web worker实现多线程

    0.从一道题说起 var t = true; setTimeout(function(){ t = false; }, 1000); while(t){ } alert('end'); 1 2 3 4 ...

  9. Spring和SpringMVC父子的容器之道---[上篇]

    Spring和SpringMVC作为Bean管理容器和MVC层的默认框架,已被众多WEB应用采用,而在实际开发中,由于有了强大的注解功能,很多基于XML的配置方式已经被替代,但在实际项目中,我们经常会 ...

  10. Python中创建对象的方法

    源引:Python编程实践 示例类: class Point: __slots__=('x','y') def __init__(self,x,y): self.x=x self.y=y def ma ...