Its my drawable folder。我有一个Android应用程序。我可以run
这个应用程序在Api 27
银河手机emulator
。我的工具的脱口秀显示出准确性。但是,当我在平板电脑模拟器上运行相同的应用程序时,我看到以下错误。平板电脑模拟器api级别22.这些错误只发生在平板电脑模拟器中,我特别指出。推介都在软件中。
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)
我的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>
和我的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>
我的地方用于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());
}
解:
代替:
toolbar.setBackground(getResources().getDrawable(R.drawable.ic_customer_toolbar));
写:
getSupportActionBar().setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ic_customer_toolbar));
如果你在片段使用中使用它:getActivity()
而不是context
试试看它是否有效。