The inflate exception is not actually the problem but really comes from another deeper issue in your layout that is then wrapped in an InflateException
.
A common issue is an out of memory exception when trying to inflate an ImageView
loading a drawable resource. If one of these resources has a high pixel resolution it would take a lot of memory causing then an inflate exception.
So basically verify that the pixel resolution in all your image drawables is just the minimum necessary for your layout.
This can also happen if you use a VectorDrawable
using support library and forgot to use app:srcCompat
instead of android:src
Exact error is: Binary XML file line #XX: Error inflating class ImageView
See that link
ViewFlipper
loads all images into memory during layout inflating. Because my images are big it takes many memory, I replaced ViewFlipper
with ImageSwitcher
which can change the images with animation like ViewFlipper
but it loads only one image at the time.
I had the same error when creating custom view with only one constructor, try to define all constructor for your custom views.
public CustomWebView(Context context) {
super(context);
init();
}
public CustomWebView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
I know the question is already answered but still I'm posting with thought that may someone run into this kind of problem.
In my case problem is i'm loading my application to phone which refer layouts from res/layout/ folder and values for @dimens from res/values/dimens here it's font_22 which it's trying to access and it's define in res/values-xlarge/dimens.
I'm actually updating UI of existing project.
I ran into this problem because I'm using IDE Eclipse where I ctrl+space for hint while writing xml for layout folder it displays all values from values as well as values-xlarge folder regardless of for which folder I'm writing.
I also know that the values in both files should be same to mapped for different screens.
Hope this may help someone run into this kind of silly problem.
I encountered the same bug and found the root reason is:
Use Application Context to inflate view.
Inflating with Activity Context fixed the bug.
I found the same error, and it took two days to identify what the error was.
The error was simply because I was trying to use: android:background
Rather than: app:srcCompat
in an SVG file.
In your case, I believe this is it
<ImageView
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/tour_11" <-- the error is here !
/>
I recommend using it this way
add this to your build.gradle app
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
and
<androidx.appcompat.widget.AppCompatImageView <-- use **AppCompatImageView** not **ImageView**
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/tour_11"
/>
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With