API 22出错,但API 26出错。为什么?

时间:2017-12-25 12:07:13

标签: java android api

我有一个非常适合API 26的应用程序,但是当我运行API 22时,应用程序会停止并显示以下错误消息:

12-25 11:59:38.536 3075-3075/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.example.mickael.gestioclientel, PID: 3075
 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mickael.gestioclientel/com.example.mickael.gestioclientel.MainActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
     at android.app.ActivityThread.access$800(ActivityThread.java:151)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:135)
     at android.app.ActivityThread.main(ActivityThread.java:5254)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
     at com.example.mickael.gestioclientel.MainActivity.onCreate(MainActivity.java:68)
     at android.app.Activity.performCreate(Activity.java:5990)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5254) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
  Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f07006a
     at android.content.res.Resources.getValue(Resources.java:1266)
     at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:330)
     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
     at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
     at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:58)
     at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
     at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
     at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
     at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
     at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
     at com.example.mickael.gestioclientel.MainActivity.onCreate(MainActivity.java:68) 
     at android.app.Activity.performCreate(Activity.java:5990) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5254) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

第68行是:

setContentView(R.layout.activity_main);

这里是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


    <LinearLayout
        android:id="@+id/layoutHead"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:id="@+id/cardSort"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp">

            <SearchView
                android:id="@+id/maBtnSearch"
                android:layout_width="235dp"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignTop="@+id/maMenuSort"
                android:layout_margin="2dp"
                android:animateLayoutChanges="true"
                android:iconifiedByDefault="false"
                android:queryBackground="@android:color/transparent"
                android:queryHint="@string/hint_search_view" />
        </android.support.v7.widget.CardView>


        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="52dp"
            android:layout_alignParentEnd="true"
            android:layout_alignTop="@+id/cardSort"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp">

            <RelativeLayout
                android:id="@+id/buttonSort"
                android:layout_width="wrap_content"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/maMenuSort"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="18dp"
                    android:text="@string/date_added"
                    android:textSize="14sp" />

                <ImageView
                    android:id="@+id/maSortBtn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignTop="@+id/maMenuSort"
                    android:layout_marginRight="5dp"
                    android:adjustViewBounds="true"
                    android:maxHeight="20dp"
                    android:maxWidth="20dp"
                    app:srcCompat="@drawable/fleche_ics"
                    android:contentDescription="TODO"
                    tools:ignore="ContentDescription" />
            </RelativeLayout>
        </android.support.v7.widget.CardView>
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/empty_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/the_list_is_empty" />

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="#80000000" />
    </RelativeLayout>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/navigationView"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start">


    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

问题出在哪里?

1 个答案:

答案 0 :(得分:0)

确保在xml文件中使用以下作为ImageView的属性:app:srcCompact而不是android:src来定义你的图像。