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.
Check vector drawable <path>. Sometimes this happens when <path> tag in XML file is too long.
Try to move your image from drawable to drawable-nodpi.
UPDATE
Try to use AppCompatResources.getDrawable(view.getContext(), id); when getting drawable
Related
I'm having some problems with Android Studio at the moment because I recently started using "Vector Assets". I've done absolutely everything necessary to display them correctly in my application (using the app:srcCompat="" in the xml, android {defaultConfig {vectorDrawables.useSupportLibrary true}} in the build.gradle, and AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); in the onCreate() method before setContentView()).
The svg files I imported into Android Studio do not have errors themselves, I can see the result without any problem in an ImageView with the wizard. The only problem comes when I run my application and it arrives at the time to draw the svg. Some of my svg's still work, while others don't, so I think some of them take too long to process.
Here is the error :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.retroverse.bataille_corse, PID: 18807
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.retroverse.bataille_corse/com.retroverse.bataille_corse.MenuPrincipal}: android.view.InflateException: Binary XML file line #127: Binary XML file line #127: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3120)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1840)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.view.InflateException: Binary XML file line #127: Binary XML file line #127: Error inflating class ImageView
Caused by: android.view.InflateException: Binary XML file line #127: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: Drawable com.retroverse.bataille_corse:drawable/card_49_en with resource ID #0x7f060099
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/card_49_en.xml from drawable resource ID #0x7f060099
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:854)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:634)
at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:329)
at android.content.res.Resources.getDrawableForDensity(Resources.java:902)
at android.content.res.Resources.getDrawable(Resources.java:841)
at android.content.Context.getDrawable(Context.java:644)
at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:454)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:144)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:132)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:187)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:107)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.retroverse.bataille_corse.MenuPrincipal.onCreate(MenuPrincipal.java:24)
at android.app.Activity.performCreate(Activity.java:7232)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2965)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3120)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1840)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.IllegalArgumentException: R is not a valid verb. Failure occurred at position 2 of path: STRING_TOO_LARGE
at android.util.PathParser.nCreatePathDataFromString(Native Method)
at android.util.PathParser.access$200(PathParser.java:24)
at android.util.PathParser$PathData.<init>(PathParser.java:76)
at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:2016)
at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1967)
at android.graphics.drawable.VectorDrawable.inflateChildElements(VectorDrawable.java:819)
at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:717)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1332)
at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1291)
at android.content.res.ResourcesImpl.createFromXmlForDensity(ResourcesImpl.java:1506)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:838)
... 41 more
The most important line, I think, is Caused by: java.lang.IllegalArgumentException: R is not a valid verb. Failure occurred at position 2 of path: STRING_TOO_LARGE.
We also know that this svg was caught in the middle (its size is 187 kilobytes). So I think my SVG file (even imported in Android Studio by "Vector Asset") is too heavy.
As we are told here, the STRING_TOO_LARGE issue appears when the string "is longer than 0x7FFF = 32767 characters". (In the reproduction part)
Indeed, the only svg to work in my application are lighter than 32 kb, which could explain this.
But I really need to display this svg (don't offer to convert it to png!) correctly, and if possible without optimizing its paths.
Any help would be welcome!
I found the answer (at last...).
Actually, there is no real problem with Vector Assets over 32 kb, it all depends on what is in the code. I should have paid more attention to the warnings than usual I don't always look at...
I discovered inside my svg a path data with a path of more than 40kb (in one string so). The fact is that, according to the site in the question, a String can't have more than (about) 32k characters or the whole string used in any xml file will be replaced by "STRING_TOO_LARGE". Anyway, by just removing this line here, I can draw the vector perfectly well (while it is still 250 kb, but now incomplete).
What's quite surprising is that Android Studio only displays a warning (where the string is longer than 32k characters) just to make me understand that an svg with a long path can be slow to display, instead of warning me that the path will be corrupted because it's too long (or even better turn this warning into an error in the IDE, to avoid an unpleasant surprise).
Thanks to #TheBigBadBoy I splitted long SVG path into several segments. I opened XML file of the image and divided the path by M symbol (see also how to split one path into two paths in svg).
<path
android:fillColor="#ffffff"
android:fillType="evenOdd"
android:pathData="M40.255,47.8897C40.1686, ... ,47.8897ZM38.7713,40.2642L38.8362, ..., 46.0978Z"
/>
You can see that each segment starts with M and ends with Z. You can retain about 20Kb in the first path and cut the tail. Then paste the tail into the second path. Make so many paths that all of them become less than 32 Kb.
So, you will get:
<path
android:fillColor="#ffffff"
android:fillType="evenOdd"
android:pathData="M40.255,47.8897C40.1686, ... ,47.8897Z"
/>
<path
android:fillColor="#ffffff"
android:fillType="evenOdd"
android:pathData="M38.7713,40.2642L38.8362, ..., 46.0978Z"
/>
I've looked all over stackoverflow and no question was able to solve my problem.
I'm trying to play an animated vector drawable on a device with API 15 but I keep getting the following runtime exception:
com.karim.test E/AvdcInflateDelegate: Exception while inflating <animated-vector>
android.content.res.Resources$NotFoundException: File res/drawable-ldpi-v4/feedback.png from xml type xml resource ID #0x7f020066
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2152)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
at android.content.res.Resources.getXml(Resources.java:906)
at android.support.graphics.drawable.VectorDrawableCompat.create(VectorDrawableCompat.java:408)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.inflate(AnimatedVectorDrawableCompat.java:356)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.createFromXmlInner(AnimatedVectorDrawableCompat.java:162)
at android.support.v7.widget.AppCompatDrawableManager$AvdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:905)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:356)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:428)
at com.karim.test.MainActivity.onCreate(MainActivity.java:210)
Caused by: java.io.FileNotFoundException: Corrupt XML binary file
at android.content.res.AssetManager.openXmlAssetNative(Native Method)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:487)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2134)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
at android.content.res.Resources.getXml(Resources.java:906)
at android.support.graphics.drawable.VectorDrawableCompat.create(VectorDrawableCompat.java:408)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.inflate(AnimatedVectorDrawableCompat.java:356)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.createFromXmlInner(AnimatedVectorDrawableCompat.java:162)
at android.support.v7.widget.AppCompatDrawableManager$AvdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:905)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:356)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:428)
at com.karim.test.MainActivity.onCreate(MainActivity.java:210)
android.content.res.Resources$NotFoundException: File res/drawable/animated_feedback_left.xml from drawable resource ID #0x7f020065
at android.content.res.Resources.loadDrawable(Resources.java:1923)
at android.content.res.Resources.getDrawable(Resources.java:664)
at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:422)
at com.karim.test.MainActivity.onCreate(MainActivity.java:204)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag animated-vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:863)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
at android.content.res.Resources.loadDrawable(Resources.java:1920)
at android.content.res.Resources.getDrawable(Resources.java:664)
at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:422)
at com.karim.test.MainActivity.onCreate(MainActivity.java:204)
I'm using the same resources from my previous question that you can find over here Animated Vector Drawable not working with API 15
Also I've tested instead of using ImageView to use AppCompatImageView but still same error.
I've been debugging this error and it fails on the following statement:
final XmlPullParser parser = res.getXml(resId);
inside:
public static VectorDrawableCompat create(#NonNull Resources res, #DrawableRes int resId, #Nullable Theme theme)
method of VectorDrawableCompat verion 23.3.0.
It seems that I'm having an issue with compatibility. At some point Android decides to use the XML parsing of API 15 instead of using the compat version. Any ideas on how I can solve this annoying problem?
Update:
I followed Chris Banes blog and still no luck. Basically I've updated the compat libraries to 23.4.0 and I used the following in my activity:
static {
AppCompatDelegate.setCompatVectorFromSourcesEnabled(true);
}
Inflating Drawable's
`VectorDrawable` and `AnimatedVectorDrawable` in this support library can be inflated in this way:
Calling static getDrawable() methods:
//This will only inflate a drawable with <vector> as the root element
VectorDrawable.getDrawable(context, R.drawable.ic_arrow_vector);
//This will only inflate a drawable with <animated-vector> as the root element
AnimatedVectorDrawable.getDrawable(context, R.drawable.ic_arrow_to_menu_animated_vector);
// This will inflate any drawable and will auto-fallback to the lollipop implementation on api 21+ devices
ResourcesCompat.getDrawable(context, R.drawable.any_drawable);
If inflating the Drawable in java code, it is recommended to always use ResourcesCompat.getDrawable() as this handles Lollipop fallback when applicable. This allows the system to cache Drawable ConstantState and hence is more efficient.
The library has the following morph (bi-directional) animations :
Play-Pause morph animation
Play-Stop morph animation
Arrow-Hamburger menu morph animation
As you can see, I produced the above image on my API 16 phone:
import com.wnafee.vector.compat.AnimatedVectorDrawable;
mdrawable = (AnimatedVectorDrawable) AnimatedVectorDrawable.getDrawable(this.getApplicationContext(), R.drawable.consolidated_animated_vector);
Look at the github README for vector-compat here: https://github.com/wnafee/vector-compat
This will fix your problem (down to API 14) if you merge it with your app module's build.gradle dependencies (usually at the end of file):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Trying to FIX Binary XML file line #2: invalid drawable tag animated-vector
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
//not needed
// compile 'com.android.support:support-vector-drawable:25.0.0'
compile 'com.wnafee:vector-compat:1.0.5'//*******holy grail *******https://github.com/wnafee/vector-compat
// Failed to resolve: com.android.support:support-animated-vector-drawable:25.0.0
//not needed
// compile 'com.android.support:support-animated-vector-drawable:25.0.0'
}
There is support library 25.4.0 and it's intended to solve all our problems. For example it finally supports path morphing!
To use it add:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
inside your project gradle file, and accordingly dependency itself:
compile 'com.android.support:support-v4:25.4.0'
After that you can use vector drawable animation with path morphing (which is often the culprit behind "invalid drawable tag animated-vector") in below manner (a little Kotlin code):
val drawable = AnimatedVectorDrawableCompat.create(this, R.drawable.vector_drawable)
imageView.setImageDrawable(drawable) // You may use usual ImageView class, no Compat necessary.
drawable.start()
This question already has answers here:
Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0
(31 answers)
Closed 6 years ago.
Recently android support library was updated to 23.2.0. After downloading android sdk and updating android design support library into 23.2.0, this error happens repeatedly. My project can't even be compiled. The complete error log says:
03-02 12:00:04.945 9324-9324/com.creditease.zhiwang.debug E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.creditease.zhiwang.debug/com.creditease.zhiwang.activity.TabContainerActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5528)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.content.res.Resources.loadDrawable(Resources.java:2974)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:184)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:91)
at android.support.v7.app.ToolbarActionBar.<init>(ToolbarActionBar.java:74)
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:210)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:119)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:300)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:265)
at com.creditease.zhiwang.activity.TabContainerActivity.onCreate(TabContainerActivity.java:107)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5528)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
at android.content.res.Resources.loadDrawable(Resources.java:2970)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:184)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:91)
at android.support.v7.app.ToolbarActionBar.<init>(ToolbarActionBar.java:74)
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:210)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:119)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:300)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:265)
at com.creditease.zhiwang.activity.TabContainerActivity.onCreate(TabContainerActivity.java:107)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5528)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
This error was thrown by setSupportActionBar(toolbar); whereas it didn't happen at 23.0.1 of android design library 23.2.0. Meanwhile according this log, I guessed this drawable was removed since android design library 23.2.0.
So, could someone told me why is this happening?
I think you need to make changes in your gradle.
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
You’ll note this new attribute only exists in the version 2.0 of the Gradle Plugin. If you are using Gradle 1.5 you’ll instead use
// Gradle Plugin 1.5
android {
defaultConfig {
// Stops the Gradle plugin's automatic rasterization of vectors
generatedDensities = []
}
// Flag to tell aapt to keep the attribute ids around
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
I found similar question here.
See Support Vector Drawables and Animated Vector Drawables in Android Support Library update.
I hope its help you.
As per as the documentation of Google's support library for 24.0.0, they have changed the vector drawable library to what it was before:
Added AppCompatDelegate.setCompatVectorFromResourcesEnabled() method to re-enable usage of vector drawables in DrawableContainer objects on devices running Android 4.4 (API level 19) and lower. See AppCompat v23.2 — Age of the vectors! for more information.
I faced the same issue and my SVG statelist drawables used in my project were working just fine till Marshmallow devices.
Later when I got the crash for the same in Android N, I realized that the svgs were a bit corrupted and contained characters like: � and this caused the crash.
But these were not reflected in Android Marshmallow and prior devices.
Make sure your vector drawable doesn't contain any of those characters as the way of parsing has been changed from the library 24.0.0. So vector drawables working fine till Marshmallow might not work in Nougat devices.
Hope this helps :)
I solve this problem by updating my support library from
'com.android.support:appcompat-v7:23.2.0'
'com.android.support:design:23.2.0'
to the same dependencies of 23.2.1.
When I met the problem, I had not made any changes in my module built by Android Studio.
So I was so confused then I tried to update android support library.
After updating, please remember to sync your build.gradle
I solved the issue as follows:
Try with changing styles.xml to
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
This is because if style requires ActionBar there are chances of not finding abc_back button but with no action bar problem is solved
This worked for me: Replace the com.android.support:design version in build.gradle with one that works. Find which version works by creating a new project from scratch in Android Studio and using the version from that.
I had this problem when I added a Navigation Drawer Activity from the File->New->Activity menu to an older project with Android Studio.
Android Studio added a dependency like so:
compile 'com.android.support:design:24.0.0-alpha1'
(I'm not sure of the exact version but it had '24' and 'alpha').
I then created a new dummy project, specifying a Navigation Drawer Activity in the new project wizard. I noticed that the new project had a different dependency: compile 'com.android.support:design:23.2.1'
So I took this dependency and put it in the first project, and the problem was solved.
Source - http://android-developers.blogspot.in/2016/02/android-support-library-232.html
when using AppCompat with ImageView (or subclasses such as ImageButton
and FloatingActionButton), you’ll be able to use the new app:srcCompat
attribute to reference vector drawables (as well as any other drawable
available to android:src):
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_add" />
where you can define your app in your root element as
xmlns:app="http://schemas.android.com/apk/res-auto"
I've had this issue because my Manifest file had style that was defined only in v21 style. Not sure why it was pointing at this type of error but someone may find this helpful.
We got a crash log from Google Play and it seems some drawable in drawable-xhdpi-v4 is not found. However, we didn't have a drawable-xhdpi-v4 folder and do have edit_bg.9.png in res/drawable-xhdpi/. I found this post after searching, but it seems not helpful and no accepted answers there.
Thanks for any advice.
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/edit_bg.9.png from drawable resource ID #0x7f0200bb
at android.content.res.Resources.loadDrawable(Resources.java:2172)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3589)
at android.widget.TextView.<init>(TextView.java:642)
at android.widget.EditText.<init>(EditText.java:60)
at android.widget.EditText.<init>(EditText.java:56)
... 29 more
Caused by: java.io.FileNotFoundException: res/drawable-xhdpi-v4/edit_bg.9.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:421)
at android.content.res.Resources.loadDrawable(Resources.java:2163)
... 34 more
I have an App with over 100.000 Users. But on some devices (~50) I get a strange exception. The stack traces says, that there is an drawable not found.
Here is the stack trace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{mindmApp.the.big.bang.theory.quiz/mindmApp.the.big.bang.theory.quiz.GameNormalActivity}: android.view.InflateException: Binary XML file line #237: Error inflating class
...
Caused by: android.view.InflateException: Binary XML file line #237: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
...
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 28 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/textviewxml_joker.xml from drawable resource ID #0x7f02003d
at android.content.res.Resources.loadDrawable(Resources.java:1956)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.(View.java:2841)
at android.widget.TextView.(TextView.java:580)
at android.widget.TextView.(TextView.java:573)
I have no idea why this drawable (it's a xml-file) is not found.
The binary XML file line #237 is:
<TextView
android:id="#+id/textViewSkip"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:background="#drawable/textviewxml_joker"
android:gravity="center"
android:text="#string/tvSkip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/color_textview"
android:textSize="22sp" />
And here is the textviewxml_joker.xml file:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/textview_joker_pressed"
android:state_pressed="true"/>
<item android:drawable="#drawable/textview_joker"/>
</selector>
Have anybody an idea t osolve this problem?
Best Regards!
If your textviewxml_joker.xml file isn't in drawable, but rather in a drawable-* folder, then those few devices that get the error may not meet the conditions to use the drawable-* folder.
Put it in drawable as well and it should fix it.
This could also happen if the resource you are referring to (lets call it ResA) is in-turn referring to a resource which is missing (lets call it ResB).
Android will raise the ResourceNotFoundException for ResA even though whats really missing is ResB. Such is life!
In my case, ResB was defined in the values-swxxxdp but not in values. Hence I was getting this exception on phones but not on tablets.
If you have multiple resource folders, make sure that Android finds your drawable xml for every possible qualifier combination (Providing Resources). Looking at the device types that have this error might give you a hint where to look.