gpt4 book ai didi

android - fragment Activity 的运行时错误

转载 作者:搜寻专家 更新时间:2023-11-01 09:11:36 25 4
gpt4 key购买 nike

我正在尝试重新创建 FragmentPagerSupport例如,但我不断收到错误消息,而且我不知道它要求的是什么。

它是这样做的

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
View tv = v.findViewById(R.id.text);
((TextView)tv).setText("Fragment #" + mNum);
return v;
}

然后它抛出运行时错误

这是我的 fragment_pager_list

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

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />



<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true" >

</ListView>

</RelativeLayout>

这是我的主要任务

<?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="vertical" >

<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/pager"/>
</LinearLayout>

错误

10-25 18:46:02.514: E/AndroidRuntime(7074): FATAL EXCEPTION: main
10-25 18:46:02.514: E/AndroidRuntime(7074): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.ListFragment.ensureList(ListFragment.java:344)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.ListFragment.onViewCreated(ListFragment.java:145)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:858)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1053)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1371)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:429)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:104)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.view.ViewPager.populate(ViewPager.java:692)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:851)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.View.measure(View.java:8330)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.View.measure(View.java:8330)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.View.measure(View.java:8330)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.View.measure(View.java:8330)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.View.measure(View.java:8330)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.view.ViewRoot.handleMessage(ViewRoot.java:1860)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.os.Looper.loop(Looper.java:123)
10-25 18:46:02.514: E/AndroidRuntime(7074): at android.app.ActivityThread.main(ActivityThread.java:3839)
10-25 18:46:02.514: E/AndroidRuntime(7074): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 18:46:02.514: E/AndroidRuntime(7074): at java.lang.reflect.Method.invoke(Method.java:507)
10-25 18:46:02.514: E/AndroidRuntime(7074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
10-25 18:46:02.514: E/AndroidRuntime(7074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
10-25 18:46:02.514: E/AndroidRuntime(7074): at dalvik.system.NativeStart.main(Native Method)

最佳答案

android:id="@+id/list" 替换为 android:id="@android:id/list"

关于android - fragment Activity 的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7896914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com