原因:android.content.res.Resources$NotFoundException:来自可绘制资源 ID #0x7f02007e 的文件 res/drawable/ic_email_
Posted
技术标签:
【中文标题】原因:android.content.res.Resources$NotFoundException:来自可绘制资源 ID #0x7f02007e 的文件 res/drawable/ic_email_black.xml【英文标题】:Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_email_black.xml from drawable resource ID #0x7f02007e 【发布时间】:2018-01-21 08:23:48 【问题描述】:当我在模拟器中测试时它工作正常,当在真实设备中测试它时 Android4.4(19) 它给出了这个日志错误 我尝试了许多替代解决方案,但它不起作用。
另外加AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
到 .Java 文件。
我的 Gradle 版本是 `distributionUrl=https://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
这是我的日志错误
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:720)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.redrockdigimark.doot.activities.OwnerLogin.onCreate(OwnerLogin.java:27)
at android.app.Activity.performCreate(Activity.java:5442)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_email_black.xml from drawable resource ID #0x7f02007e
at android.content.res.Resources.loadDrawable(Resources.java:3451)
at android.content.res.TypedArray.getDrawable(TypedArray.java:614)
at android.widget.TextView.<init>(TextView.java:896)
at android.widget.EditText.<init>(EditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:62)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:58)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.redrockdigimark.doot.activities.OwnerLogin.onCreate(OwnerLogin.java:27)
at android.app.Activity.performCreate(Activity.java:5442)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:969)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:913)
at android.content.res.Resources.loadDrawable(Resources.java:3447)
at android.content.res.TypedArray.getDrawable(TypedArray.java:614)
at android.widget.TextView.<init>(TextView.java:896)
at android.widget.EditText.<init>(EditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:62)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:58)
`
应用级分级:
apply plugin: 'com.android.application'
android
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig
applicationId "com.redrockdigimark.doot"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
buildTypes
release
shrinkResources true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
exclude group: 'com.android.support', module: 'support-annotations'
)
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-vector-drawable:26.0.0-alpha1'
compile 'com.android.support:support-v4:26.0.0-alpha1'
------
testCompile 'junit:junit:4.12'
apply plugin: 'com.google.gms.google-services'
Xml 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:background="@drawable/loginbg"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:layout_margin="40dp">
<EditText
android:id="@+id/et_email"
android:layout_
android:layout_
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="194dp"
android:background="@color/white"
android:drawableStart="@drawable/ic_email_black"
android:drawablePadding="5dp"
android:hint="Email"
android:padding="10dp" />
<EditText
android:id="@+id/et_password"
android:layout_
android:layout_
android:layout_below="@+id/et_email"
android:layout_marginTop="20dp"
android:background="@color/white"
android:drawableStart="@drawable/ic_logout"
android:drawablePadding="5dp"
android:drawableTint="@color/primary"
android:hint="Password"
android:padding="10dp" />
<TextView
android:id="@+id/txt_forgot_pwd"
android:layout_
android:layout_
android:layout_alignParentEnd="true"
android:layout_below="@+id/et_password"
android:layout_marginEnd="10dp"
android:layout_marginTop="20dp"
android:text="Forgot Password"
android:textColor="@color/white" />
</RelativeLayout>
编辑: ic_email_black.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:
android:
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFC107"
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
</vector>
【问题讨论】:
android.content.res.Resources$NotFoundException: 来自可绘制资源 ID #0x7f02007e 的文件 res/drawable/ic_email_black.xml:此错误表明 ic_email_black.xml 未添加到您的项目中。 它在项目drawable文件夹中 你如何在你的xml中添加,尝试用app:srcCompat添加 我使用android:drawableLeft="@drawable/ic_email_black"
,因为我想将drawable添加到EditText。
请阅读:***.com/questions/35761636/…。还有一个提示:始终阅读整个堆栈跟踪,而不仅仅是第一行。
【参考方案1】:
它在 EditText 上显示错误。
Binary XML file line #11: Error inflating class EditText
您的矢量绘图也可以正常工作。可能是 Android 19 设备的问题。
尝试使用AppcompatEditText
而不是EditText
<android.support.v7.widget.AppCompatEditText
android:id="@+id/et_email"
android:layout_
android:layout_
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="194dp"
android:background="@color/white"
android:drawableStart="@drawable/ic_email_black"
android:drawablePadding="5dp"
android:hint="Email"
android:padding="10dp"/>
希望对你有帮助:)
【讨论】:
转到您的项目文件夹并删除构建文件夹并重建您的项目。 您能发布您在项目中使用资源文件 ic_email_black.xml 的位置吗?我需要查看您使用的编辑文本 XML。 当我删除android:drawableStart="@drawable/ic_email_black"
它工作正常。现在如何将图标添加到 EditText
看起来不错。也发布您的 ic_email_black.xml。这样我们就可以找到错误了。
别忘了清理你的项目以上是关于原因:android.content.res.Resources$NotFoundException:来自可绘制资源 ID #0x7f02007e 的文件 res/drawable/ic_email_的主要内容,如果未能解决你的问题,请参考以下文章
“'NSInternalInconsistencyException' 的替代原因,原因:'此 NSPersistentStoreCoordinator 没有持久存储。'”