android.content.res.Resources$NotFoundException API 级别 19

android.content.res.Resources$NotFoundException API Level 19

有人知道为什么我在 android 上测试我的 apk 7 完美,在 5 完美上测试......但是如果我在 4.4.2 上测试当从 drawable 加载图标时崩溃......这是我的 apk 崩溃的代码:

Drawable drawable = null;
        Integer id_icon = 0;
        if (materia.getIcon() != null) {
            id_icon = getResources().getIdentifier(materia.getIcon(), "drawable", "com.package");
        } else {
            Integer size = materia.getTopics().size();
            if (size >= 1 && size <= 9) {
                id_icon = getResources().getIdentifier("ic_filter_" + size.toString() + "_black", "drawable", "com.package");
            } else {
                if (size > 9) {
                    id_icon = getResources().getIdentifier("ic_filter_9_plus_black", "drawable", "com.package");
                }
            }
        }
//This line is where throw the exception.... but why??
        if (id_icon > 0) drawable = (Drawable) getResources().getDrawable(id_icon);
        MenuItem menuItem = sm.add(R.id.list_materiales, Menu.NONE, i, Html.fromHtml(materia.getMaterial())).setCheckable(true).setChecked(false);
        menuItem.setIcon(drawable);
        storageKeys.addKeyMaterial(materia.getKey());

这是我的 gradle 配置文件:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
   compileSdkVersion 26
   defaultConfig {
       applicationId "com.package"
       minSdkVersion 19
       targetSdkVersion 19
       versionCode 1
       versionName "1.0"
       vectorDrawables.useSupportLibrary = true
   }
    buildTypes {
       release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.pro'
        }
    }
    compileOptions {
       targetCompatibility 1.8
       sourceCompatibility 1.8
    }
}
dependencies {
   implementation fileTree(include: ['*.jar'], dir: 'libs')
   implementation 'com.android.support:cardview-v7:26.1.0'
   implementation 'com.android.support:recyclerview-v7:26.1.0'
   //
   implementation 'com.android.support:appcompat-v7:26.1.0'
   implementation 'com.android.support:design:26.1.0'
   implementation 'com.android.support.constraint:constraint-layout:1.0.2'  'com.android.support.test.espresso:espresso-core:+'
   implementation 'com.android.support:support-v4:26.1.0'
   implementation 'com.android.support:support-vector-drawable:26.1.0'
}

提前致谢..抱歉我的英语不好...

您使用的是矢量图吗?

如果是,请参阅此 post。

否则你应该post错误信息。