知识的价值不在于占有,而在于使用。这篇文章主要讲述android.content.res.Resources $ NotFoundException API等级19相关的知识,希望能为你提供帮助。
有人知道为什么当我在android 7上测试我的apk完美,测试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 conf:
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'
}
先谢谢了...抱歉我的英语不好......
答案你在使用矢量绘图吗?
如果有的话请参考这篇文章。
vector drawables on pre lollipop crash
【android.content.res.Resources $ NotFoundException API等级19】否则,您应该发布错误消息。
推荐阅读
- Android(菜单中的圆角)
- 如何在Android ListView中为菜单项创建图标()
- Android中的自定义选项菜单栏问题
- Build.gradle无法解析com.android.support
- DotNetCore.NPOI和.Net Core 2 MVC Web App
- 什么填充ScriptResourceMapping()
- 当jboss 7服务器启动时,在jndi查找中获取appname
- 无法引用webapp struts中的资源
- Android Firebase FireStore实时更新分页