Spi*_*idy 15 android android-1.6-donut android-fragments android-support-library
仅当为3.0之前的设备使用兼容性库时才会发生这种情况
我收到一个我无法确定的错误.我有一个带有ListFragment和标准片段的Activity.它就像Android Dev Guide的Developers部分中提供的示例一样.
ListFragment子类(未覆盖任何函数)
public class ItemListFragment extends ListFragment
Run Code Online (Sandbox Code Playgroud)
主要活动
public class ItemViewerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item_viewer);
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
来自LogCat的错误消息
ERROR/AndroidRuntime:引起:java.lang.ClassCastException:org.example.ItemListFragment无法强制转换为android.app.Fragment
Spi*_*idy 35
经过一番严肃的谷歌搜索,我发现了一篇文章指出了一个不错的小花絮.使用兼容性库时,使用片段的活动必须扩展FragmentActivity.一旦我这样做,错误就不再出现了.
| 归档时间: |
|
| 查看次数: |
6310 次 |
| 最近记录: |