膨胀类片段时出错找不到类android.view.fragment,但我正在包含兼容性库?

膨胀类片段时出错找不到类android.view.fragment,但我正在包含兼容性库?,android,android-layout,Android,Android Layout,虽然我正在使用兼容性库,但我看到android.view.fragment的类未找到异常。编译良好,但崩溃。在3.0之前,我是否应该使用其他软件包?我已经将所有片段类更改为android.support.v4.app.Frament,但由于布局中的原因,它仍然崩溃。我的SDK是4.03,但设备是2.3 这里是布局图 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://sc

虽然我正在使用兼容性库,但我看到android.view.fragment的类未找到异常。编译良好,但崩溃。在3.0之前,我是否应该使用其他软件包?我已经将所有片段类更改为android.support.v4.app.Frament,但由于布局中的原因,它仍然崩溃。我的SDK是4.03,但设备是2.3

这里是布局图

    <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<fragment
    android:id="@+id/frag_series"
    android:layout_width="200dip"
    android:layout_height="match_parent"
    android:layout_marginTop="?android:attr/actionBarSize"
    class="com.authorwjf.hello_fragments.ListFrag" />
<fragment
    android:id="@+id/frag_capt"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.authorwjf.hello_fragments.DetailFrag" />
</LinearLayout>

在布局XML中执行相同的操作:

<android.support.v4.app.Fragment />


另外,请注意大小写。

我在使用片段标记时遇到了类似的问题,因为我在FragmentActivity中错过了对super.onCreate()的调用。添加它解决了问题:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}

检查您的活动是否扩展了碎片活动?android.support.v4.app.FragmentActivity确切地说

我的SDK是4.03,但设备是2.3

我也有这个问题。然后我知道,当我们在较低版本的设备上运行时,我们需要在构建路径中包含support jar(android.support.v4)

在将Jar包含到构建路径中之后,我们还需要确保Jar文件位于排序的顶部(使用eclipse的Order和Export选项)


这两件事解决了我的问题。。希望能有所帮助。

我遇到了同样的问题,下面是解决方案。

使用片段的活动需要扩展
FragmentActivity
,而不仅仅是
activity



在活动的布局中,您仍然可以使用
而不是

现在我得到08-08 15:27:28.653:E/AndroidRuntime(13644):由:java.lang.NoSuchMethodException:Fragment(上下文,属性集)引起,这是因为没有这样的构造函数。请参阅:@CodeDroid您是否解决了java.lang.NoSuchMethodException:Fragment(上下文,属性集)的问题?你是怎么做到的?这并没有解决我的问题,我一直在得到NoSuchMethodException,无法找到解决方法。这不是一个解决方案。这只会产生不同的错误。
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}