Custom Layout Crash InflateException
See original GitHub issueHello Chris, just wanted to start off by saying thanks for such a great library! With that in mind I’m hoping this crash report helps improve it.
I’m currently seeing a crash on a couple of Samsung devices where the apps are crashing in what seems to be a failure to inflate a xml file used in a custom layout that extends FrameLayout. Below is the stack trace I’ve collected:
android.view.InflateException: Binary XML file line #63: Error inflating class <unknown> at android.view.LayoutInflater.createView(LayoutInflater.java:626) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:162) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:146) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at android.view.LayoutInflater.inflate(LayoutInflater.java:354) at android.view.View.inflate(View.java:18474) at re.snapwi.ui.RetryLayout.init(RetryLayout.java:52) at re.snapwi.ui.RetryLayout.<init>(RetryLayout.java:31) at re.snapwi.ui.photo.PhotoGalleryFragment.onCreateView(PhotoGalleryFragment.java:116) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5602) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(NativeStart.java) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Constructor.java) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createView(LayoutInflater.java:600) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:162) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:146) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at android.view.LayoutInflater.inflate(LayoutInflater.java:354) at android.view.View.inflate(View.java:18474) at re.snapwi.ui.RetryLayout.init(RetryLayout.java:52) at re.snapwi.ui.RetryLayout.<init>(RetryLayout.java:31)
Line 52 of RetryLayout is calling inflate in the custom framelayout:
private void init(Context context) {
setLayoutTransition(new LayoutTransition());
inflate(context, R.layout.retry_framelayout, this); // This is LINE 52
progressLayout = findViewById(R.id.retryProgressLayout);
progressBarDefault = findViewById(R.id.retryProgress);
topProgressBar = findViewById(R.id.smoothProgressBar);
retryLayout = findViewById(R.id.retryButtonLayout);
mainLayout = (FrameLayout) findViewById(R.id.mainContent);
retryTextView = (TextView) findViewById(R.id.retryTextView);
retryTextView.setTextColor(retryTextColor);
retryButton = (Button) findViewById(R.id.retryButton);
mShortAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime);
}
The inflateException then points to Binary XML file line #63 which is the beginning of a ProgressBar tag
<ProgressBar
android:id="@+id/retryProgress"
style="@style/SnapwireSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
The crash is affecting the following Samsung models: SM N910G, GT N7100, SCH S960L
Issue Analytics
- State:
- Created 9 years ago
- Comments:34 (17 by maintainers)
Top GitHub Comments
So I think I might have had a breakthrough in figuring out what the root problem is… I can create the exact same crash by making my app run out of memory.
When the app is just about to run about memory and I try to load another view the app crashes with the same stack trace which at first appears to be caused by Calligraphy library but really it was because my app had a memory leak.
At the very end of my stack trace I failed to notice:
Caused by: java.lang.OutOfMemoryError at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:503) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:356) at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:379) at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:409) at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:493) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
Once I fixed this memory leak this crash went away. I hope this helps.
@marcoRS Personally whenever I write custom classes. I only provide the two arg constructor (saves you time!)
E.g.
If this works for every other device and not samsung, I would take a guess at this being an issue with your custom view and samsung devices and not calligraphy. We pass inflation off to the underling inflater. (We just get the blame for the exception).