2012-01-28 137 views
3

我试图运行采用了android的FragmentLayout示例程序:异常马上蝙蝠

坠毁马上投注做的setContentView()的minSdkVersion =“15”,获得例外低于:

Unable to start activity ComponentInfo{net.examples.HelloFragmentLayout/net.examples.HelloFragmentLayout.FragmentLayout}: android.view.InflateException: Binary XML file line #6: Error inflating class Fragment 

net.examples.HelloFragmentLayout/net.examples.HelloFragmentLayout.FragmentLayout”看起来像重复,但我不知道是什么造成了这种情况。

在我的fragment_layout.xml(下面)中,我收到一条警告:“此FrameLayout可以替换为合并标签”。不知道这是否有影响。

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

<Fragment class="net.examples.HelloFragmentLayout.TitlesFragment" 
    android:id="@+id/titles" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

</FrameLayout> 

回答

3

在布局中需要小写'f'。

<fragment>是由Activity解释的特殊标签,而不是实例化为普通类(例如,LinearLayout)。

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

<fragment class="net.examples.HelloFragmentLayout.TitlesFragment" 
    android:id="@+id/titles" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

</FrameLayout> 
+0

非常感谢杰克。 我越来越: net.examples.HelloFragmentLayout.TitlesFragment不能转换到android.support.v4.app.Fragment ...当我fragment_layout.xml有这样的: <片段类=“net.examples.HelloFragmentLayout.TitlesFragment” ... – user1174708 2012-01-28 23:42:26

+0

听起来像你是从'android.app.Fragment'而不是'android.support.v4.app.Fragment'继承。 – 2012-01-29 05:52:42