引起:android.content.res.Resources $ NotFoundException:来自可绘制资源ID的文件res / drawable / ic_email_black.xml#0x7f02007e

时间:2017-08-13 08:33:22

标签: android xml

当我在模拟器中测试它时工作正常,何时在真实设备 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) 

`

App level gradle:

   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_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/loginbg"
android:orientation="vertical">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="40dp">
    <EditText
        android:id="@+id/et_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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_width="match_parent"
        android:layout_height="wrap_content"
        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_width="wrap_content"
        android:layout_height="wrap_content"
        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:width="24dp"
    android:height="24dp"
    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>

1 个答案:

答案 0 :(得分:0)

它在EditText上显示错误。

 Binary XML file line #11: Error inflating class EditText

你的矢量drawable也工作正常。也许是 Android 19 设备的问题。

尝试使用AppcompatEditText代替EditText

<android.support.v7.widget.AppCompatEditText
        android:id="@+id/et_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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"/>

希望有所帮助:)