android.view.InflateException:二进制XML文件行#7:错误导致类<unknown> </unknown>

时间:2015-02-23 15:53:38

标签: android xml android-layout android-activity android-fragments

我发现了很多与此相关的问题,但仍然无法超越我的问题。所以我需要帮助来解决它。

我有带有2个片段的ViewPager,我尝试将ImageView添加到第二个片段,但应用程序因此错误而崩溃。顺便说一句,当我只添加TextView或Button而不使用ImageView应用程序时,ViewPager工作正常。如何解决我的问题?

感谢您的帮助!

fragment_news.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/news_content"
          android:src="@drawable/news_content"
          android:layout_marginLeft="10dp"
          android:layout_marginRight="10dp"/>


</RelativeLayout>

NewsFragment.java

public class NewsFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_news, container, false);
    }
}

错误

02-23 15:14:32.877    1233-1233/www.smartavenue.com E/AndroidRuntime﹕ FATAL 

    EXCEPTION: main
        Process: www.smartavenue.com, PID: 1233
        android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
                at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                at www.smartavenue.com.fragment.NewsFragment.onCreateView(NewsFragment.java:16)
                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.executePendingTransactions(FragmentManager.java:486)
                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
                at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
                at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
                at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
                at android.view.View.measure(View.java:16497)
                at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
                at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
                at android.view.View.measure(View.java:16497)
                at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:851)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                at android.view.View.measure(View.java:16497)
                at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.onMeasure(CustomViewAbove.java:456)
                at android.view.View.measure(View.java:16497)
                at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
                at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
                at android.view.View.measure(View.java:16497)
                at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
                at android.view.View.measure(View.java:16497)

1 个答案:

答案 0 :(得分:2)

这对我有好处:

在清单中:

ngShow

在.xml文件中,您必须删除以下代码:

<application
        android:largeHeap="true"

因为错误是内存不足错误