0

I am using vector drawables programmatically instead of png like :

getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_navigate_before_black_24dp));

Everything is working fine but the app crashes in android 4.2 & below. Am getting the following log

Caused by: android.content.res.Resources$NotFoundException: 
at android.content.res.Resources.loadDrawable (Resources.java:2842)
at android.content.res.Resources.getDrawable (Resources.java:1521)
at android.app.Activity.performCreate (Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate    (Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity  (ActivityThread.java:2218)
Caused by: org.xmlpull.v1.XmlPullParserException: 
at android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:917)
at android.graphics.drawable.Drawable.createFromXml (Drawable.java:858)
at android.content.res.Resources.loadDrawable (Resources.java:2839)

I am using gradle 3.0.1 and also added

vectorDrawables.useSupportLibrary = true

still no help.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
asish rauto
  • 637
  • 2
  • 10
  • 19

1 Answers1

6
  1. Check vector drawable <path>. Sometimes this happens when <path> tag in XML file is too long.
  2. Try to move your image from drawable to drawable-nodpi.

UPDATE

  1. Try to use AppCompatResources.getDrawable(view.getContext(), id); when getting drawable
Anton Kazakov
  • 2,740
  • 3
  • 23
  • 34