简体   繁体   中英

android.content.res.Resources$NotFoundException: File res/drawable/ic_customer_toolbar.xml from drawable resource ID #0x7f0200d7

Its my drawable folder . I have an android app. I can run this app on an Api 27 galaxy phone emulator . My tool's blurts are displaying accuracies. But when I run the same application on a tablet emulator, I see the following errors. Tablet emulator api level 22. These errors are only happening in the tablet emulator, I specifically point out. The referrals are all in the software.

E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.satisekibim.android/com.satisekibim.android.customers.CustomersActivity}: android.content.res.Resources$NotFoundException: File res/drawable/ic_customer_toolbar.xml from drawable resource ID #0x7f0200d7
                         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.content.res.Resources$NotFoundException: File res/drawable/ic_customer_toolbar.xml from drawable resource ID #0x7f0200d7
                         at android.content.res.Resources.loadDrawableForCookie(Resources.java:2479)
                         at android.content.res.Resources.loadDrawable(Resources.java:2381)
                         at android.content.res.Resources.getDrawable(Resources.java:787)
                         at android.content.res.Resources.getDrawable(Resources.java:752)
                         at com.satisekibim.android.customers.CustomersActivity.populateUI(CustomersActivity.java:21)
                         at com.satisekibim.android.activity.BaseActivity.onCreate(BaseActivity.java:60)
                         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: File res/drawable/ic_customer_toolbar_1.xml from color state list resource ID #0x7f020241
                         at android.content.res.Resources.loadColorStateList(Resources.java:2592)
                         at android.content.res.TypedArray.getColor(TypedArray.java:395)
                         at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1439)
                         at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1418)
                         at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:544)
                         at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:460)
                         at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1128)
                         at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1032)
                         at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469)
                         at android.content.res.Resources.loadDrawable(Resources.java:2381) 
                         at android.content.res.Resources.getDrawable(Resources.java:787) 
                         at android.content.res.Resources.getDrawable(Resources.java:752) 
                         at com.satisekibim.android.customers.CustomersActivity.populateUI(CustomersActivity.java:21) 
                         at com.satisekibim.android.activity.BaseActivity.onCreate(BaseActivity.java:60) 
                         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: org.xmlpull.v1.XmlPullParserException: Binary XML file line #13: invalid drawable tag gradient
                         at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:148)
                         at android.content.res.ColorStateList.createFromXml(ColorStateList.java:131)
                         at android.content.res.Resources.loadColorStateList(Resources.java:2588)
                         at android.content.res.TypedArray.getColor(TypedArray.java:395) 
                         at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1439) 
                         at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1418) 
                         at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:544) 
                         at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:460) 
                         at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1128) 
                         at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1032) 
                         at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469) 
                         at android.content.res.Resources.loadDrawable(Resources.java:2381) 
                         at android.content.res.Resources.getDrawable(Resources.java:787) 
                         at android.content.res.Resources.getDrawable(Resources.java:752) 
                         at com.satisekibim.android.customers.CustomersActivity.populateUI(CustomersActivity.java:21) 
                         at com.satisekibim.android.activity.BaseActivity.onCreate(BaseActivity.java:60) 
                         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) 
D/FA: Logging event (FE): app_exception(_ae), Bundle[{firebase_event_origin(_o)=crash, timestamp=1536607108297, fatal=1}]
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.satisekibim.android, PID: 9201
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.satisekibim.android/com.satisekibim.android.customers.CustomersActivity}: android.content.res.Resources$NotFoundException: File res/drawable/ic_customer_toolbar.xml from drawable resource ID #0x7f0200d7
                      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.content.res.Resources$NotFoundException: File res/drawable/ic_customer_toolbar.xml from drawable resource ID #0x7f0200d7
                      at android.content.res.Resources.loadDrawableForCookie(Resources.java:2479)
                      at android.content.res.Resources.loadDrawable(Resources.java:2381)
                      at android.content.res.Resources.getDrawable(Resources.java:787)
                      at android.content.res.Resources.getDrawable(Resources.java:752)
                      at com.satisekibim.android.customers.CustomersActivity.populateUI(CustomersActivity.java:21)
                      at com.satisekibim.android.activity.BaseActivity.onCreate(BaseActivity.java:60)
                      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: File res/drawable/ic_customer_toolbar_1.xml from color state list resource ID #0x7f020241
                      at android.content.res.Resources.loadColorStateList(Resources.java:2592)
                      at android.content.res.TypedArray.getColor(TypedArray.java:395)
                      at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1439)
                      at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1418)
                      at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:544)
                      at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:460)
                      at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1128)
                      at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1032)
                      at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469)
                      at android.content.res.Resources.loadDrawable(Resources.java:2381) 
                      at android.content.res.Resources.getDrawable(Resources.java:787) 
                      at android.content.res.Resources.getDrawable(Resources.java:752) 
                      at com.satisekibim.android.customers.CustomersActivity.populateUI(CustomersActivity.java:21) 
                      at com.satisekibim.android.activity.BaseActivity.onCreate(BaseActivity.java:60) 
                      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: org.xmlpull.v1.XmlPullParserException: Binary XML file line #13: invalid drawable tag gradient
                      at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:148)
                      at android.content.res.ColorStateList.createFromXml(ColorStateList.java:131)
                      at android.content.res.Resources.loadColorStateList(Resources.java:2588)
                      at android.content.res.TypedArray.getColor(TypedArray.java:395) 
                      at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1439) 
                      at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1418) 
                      at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:544) 
                      at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:460) 
                      at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1128) 
                      at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1032) 
                      at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469) 
                      at android.content.res.Resources.loadDrawable(Resources.java:2381) 
                      at android.content.res.Resources.getDrawable(Resources.java:787) 
                      at android.content.res.Resources.getDrawable(Resources.java:752) 
                      at com.satisekibim.android.customers.CustomersActivity.populateUI(CustomersActivity.java:21) 
                      at com.satisekibim.android.activity.BaseActivity.onCreate(BaseActivity.java:60) 
                      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) 

My Toolbar xml :

<android.support.v7.widget.Toolbar 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/myToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@drawable/ic_launcher_background"
    android:gravity="center"
    app:navigationIcon="@drawable/ic_left_arrow"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    android:minHeight="?attr/actionBarSize">

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


        <RelativeLayout
            android:id="@+id/linearLayoutToolbarContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:gravity="center"
            android:paddingEnd="75dp"
            android:paddingRight="75dp"
            tools:ignore="Orientation">

            <ImageView
                android:id="@+id/imageViewLogo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:src="@drawable/ic_header_logo"
                android:visibility="gone" />

            <TextView
                android:id="@+id/textViewSectionTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:fontFamily="@font/roboto_regular"
                android:gravity="center"
                android:textAlignment="center"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:textStyle="bold"
                android:visibility="gone"
                tools:text="Section Title" />

        </RelativeLayout>

        <ProgressBar
            android:id="@+id/toolbarProgressbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:padding="@dimen/app_padding_tiny"
            android:visibility="invisible" />

        <Button
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_marginEnd="22dp"
            android:background="@drawable/ic_menu_button"
            android:visibility="gone" />

        <TextView
            android:id="@+id/textViewRouteMap"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:text="Harita"
            android:textAlignment="center"
            android:textColor="@color/white"
            android:layout_marginTop="19dp"
            android:layout_marginRight="10dp"
            android:textSize="14sp"
            android:visibility="gone"/>
    </RelativeLayout>


</android.support.v7.widget.Toolbar>

And my ic_customer_toolbar xml:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="375dp"
    android:height="90dp"
    android:viewportWidth="375"
    android:viewportHeight="90">
  <path
      android:pathData="M0,0h375v90h-375z"
      android:strokeWidth="1"
      android:fillType="evenOdd"
      android:strokeColor="#00000000">
    <aapt:attr name="android:fillColor">
      <gradient 
          android:startY="-188.04688"
          android:startX="6.421875"
          android:endY="90"
          android:endX="291.6172"
          android:type="linear">
        <item android:offset="0" android:color="#FF17EAD9"/>
        <item android:offset="1" android:color="#FF479BD5"/>
      </gradient>
    </aapt:attr>
  </path>
</vector>

My place use to ic_customer_toolbar.xml :

@Override
    protected void populateUI() {
        toolbar.setBackground(getResources().getDrawable(R.drawable.ic_customer_toolbar));
        CustomersFragment customersFragment = CustomersFragment.newInstance();
        FragmentTransactionUtil.addFragment(getSupportFragmentManager(), getFragmentContainerId(), customersFragment, customersFragment.getFragmentTag());
    }

Solution:

Instead of:

toolbar.setBackground(getResources().getDrawable(R.drawable.ic_customer_toolbar));

Write:

getSupportActionBar().setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ic_customer_toolbar));

if you are using it in fragment use: getActivity() instead of context

Try and see if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM