【发布时间】:2011-05-03 19:18:36
【问题描述】:
只有在使用 3.0 之前的设备的兼容性库时才会发生这种情况
我收到一个我无法确定的错误。我有一个带有 ListFragment 和标准 Fragment 的 Activity。就像 Android 开发指南的开发者部分提供的示例一样。
ListFragment 子类(没有重写函数)
public class ItemListFragment extends ListFragment
MainActivity
public class ItemViewerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item_viewer);
}
}
MainActivity 的 Xml 布局
<?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 class="org.example.ItemListFragment"
android:id="@+id/item_list_fragment"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/item_info_frame"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
来自 LogCat 的错误消息
ERROR/AndroidRuntime: Caused by: java.lang.ClassCastException: org.example.ItemListFragment cannot be cast to android.app.Fragment
【问题讨论】:
标签: android android-fragments android-1.6-donut android-support-library