0

I have a problem with inflating, I dont know how to resolve it because it is a strange issue. I got a crash in my BaseFragment class in line 60 for samsung and huawei devices(huawei gra_l09). Code looks like below:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        int contentView = onFragmentContentView();

        if(contentView == 0)
            throw new IllegalArgumentException("onFragmentContentView must be not equal 0");

        View layout = inflater.inflate(contentView, container, false); //!!line 60
        ButterKnife.inject(this, layout);

        onCreateFragmentView(layout, container, savedInstanceState);

        return layout;
    }

I am not sure if the theme is a reason? I have used Theme.AppCompat.Light.

Fatal Exception: android.view.InflateException: Binary XML file line

2: Error inflating class

   at android.view.LayoutInflater.createView(LayoutInflater.java:633)
   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
   at com.vyda.stream.fragments.BaseFragment.onCreateView(BaseFragment.java:60)
   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5254)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763) 
   at java.lang.reflect.Constructor.newInstance(Constructor.java)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
   at android.view.LayoutInflater.createView(LayoutInflater.java:607)
   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
   at com.vyda.stream.fragments.BaseFragment.onCreateView(BaseFragment.java:60)
   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5254)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:977) > byte allocation with 3357954 free bytes and 3MB until OOM
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763)
   at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
   at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
   at android.content.res.Resources.loadDrawableForCookie(Resources.java:2480)
   at android.content.res.Resources.loadDrawable(Resources.java:2387)
   at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
   at android.view.View.<init>(View.java:3754)
   at android.view.ViewGroup.<init>(ViewGroup.java:498)
   at android.widget.RelativeLayout.<init>(RelativeLayout.java:249)
   at android.widget.RelativeLayout.<init>(RelativeLayout.java:245)
   at android.widget.RelativeLayout.<init>(RelativeLayout.java:241)
   at java.lang.reflect.Constructor.newInstance(Constructor.java)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
   at android.view.LayoutInflater.createView(LayoutInflater.java:607)
   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
   at com.vyda.stream.fragments.BaseFragment.onCreateView(BaseFragment.java:60)
   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5254)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:977)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763)

[Edit]: Whole class code: http://pastebin.com/nSCpY35Y

Community
  • 1
  • 1
Michael
  • 780
  • 1
  • 10
  • 34
  • what does onFragmentContentView() return? – Alexander May 25 '16 at 08:53
  • Also include your layout XML file - so we can also examine it and see if there aren't any problems there. – ishmaelMakitla May 25 '16 at 08:56
  • This is abstract method which is override in each child class. It returns void. general I use this method to call some init methods or inject object – Michael May 25 '16 at 08:57
  • @ishmaelMakitla I cannot put XML file because I dont know which exaclty file is wrong. Each fragment extends `BaseFragment` and in crash log I don't see XML file name :( – Michael May 25 '16 at 08:59
  • Normally, you have a layout file which includes your Fragments or their place holders - that is the layout XML you can include. What does the method `onFragmentContentView()` return? Can you maybe show us the code in this method? – ishmaelMakitla May 25 '16 at 09:18
  • This is whole code: http://pastebin.com/nSCpY35Y. I cannot check which file XML. In crashs log I see only `BaseFragment` which doesn't have own xml file – Michael May 25 '16 at 09:27
  • `BaseFragment` is abstract - so which Fragment do you instantiate (the one that extends this `BaseFragment`)? Can you at least show the code for that - I am trying to follow your call-stack to understand where the issue might be coming from. – ishmaelMakitla May 25 '16 at 09:35
  • I have ~30 fragments I am not sure which exactly you want see. From backstack you see that we dont have information about class – Michael May 25 '16 at 10:25

2 Answers2

2

Add this:

android:largeHeap="true"

in your manifest file to avoid OOM error.

Sundeep Badhotiya
  • 810
  • 2
  • 9
  • 14
0

You are having an OOM (Out Of Memory error) byte allocation with 3357954 free bytes and 3MB until OOM check the size of your images.

Alberto Méndez
  • 1,044
  • 14
  • 31