asish rauto
asish rauto

Reputation: 637

Resource not found exception for vectordrawables

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.

Upvotes: 0

Views: 1771

Answers (1)

Anton Kazakov
Anton Kazakov

Reputation: 2764

  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

Upvotes: 6

Related Questions