小编Var*_*iag的帖子

Android资源$ NotFoundException来自旧手机的可绘制资源API 18

我只是在使用Android 4.3和API 18的三星Galaxy Nexus手机上进行测试时遇到以下错误.

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_error.xml
 from drawable resource ID #0x7f020098
    at android.content.res.Resources.loadDrawable(Resources.java:2091)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
    at android.widget.TextView.<init>(TextView.java:803)
    at android.widget.EditText.<init>(EditText.java:60)
Run Code Online (Sandbox Code Playgroud)

在我的Acitivty.java文件中,我尝试使用以下方法设置我的矢量drawable:

editTextNickname.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_error, 0);
editTextNickname.setCompoundDrawables(null, null,
    ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_error), null);
Run Code Online (Sandbox Code Playgroud)

我在build.gradle文件中使用了最新的支持库,如下所示:

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'

android {
  compileSdkVersion 24
  buildToolsVersion "23.0.3"

defaultConfig {
  applicationId "com.peprally.jeremy.peprally"
  minSdkVersion 16
  targetSdkVersion 24
  versionCode 1
  versionName "1.0"
  vectorDrawables.useSupportLibrary = true
}
buildTypes {
  release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  }
  debug {
    debuggable true
  }
}

repositories {
  mavenCentral() …
Run Code Online (Sandbox Code Playgroud)

java android gradle android-support-library

4
推荐指数
1
解决办法
2800
查看次数

标签 统计

android ×1

android-support-library ×1

gradle ×1

java ×1