android.view.InflateException:二进制XML文件行 - 如何避免

时间:2016-05-25 08:51:19

标签: android android-layout android-fragments android-inflate inflate-exception

我有膨胀的问题,我不知道如何解决它,因为这是一个奇怪的问题。我在第60行的BaseFragment课程中遇到了关于三星和华为设备(huawei gra_l09)的崩溃。代码如下所示:

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;
    }

我不确定主题是否是一个原因?我使用过Theme.AppCompat.Light。

  

致命异常:android.view.InflateException:二进制XML文件行

     

2:导致类

错误
   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)

[编辑]:全班代码:http://pastebin.com/nSCpY35Y

2 个答案:

答案 0 :(得分:1)

添加:

android:largeHeap="true"
清单文件中的

以避免OOM错误。

答案 1 :(得分:0)

您正在使用OOM(内存不足错误)byte allocation with 3357954 free bytes and 3MB until OOM检查图像的大小。