gpt4 book ai didi

android - 二进制 XML 文件第 9 行 : Error inflating class fragment

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:44 24 4
gpt4 key购买 nike

在运行调用具有 fragment 的 Activity 时出现错误 inflatting fragment 错误。

CheckList 是包含listview 和Description fragment 的Activity。它的xml 代码是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">

<fragment class="com.uday.honeytest.CheckList$listview"
android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent" />

<fragment class="com.uday.honeytest.CheckList$Description"
android:id="@+id/details" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground" />

</LinearLayout>

CheckList 类是:

public class CheckList extends Activity {

static int position=0;
static CheckList check;

public void onCreate(Bundle saved){

super.onCreate(saved);
setContentView(R.layout.checklist);


}

public static class listview extends ListFragment {

View mConverView;
String[] items;



@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
xxxxxx..
return mConverView;
}
}

类似地,我在下面有描述 fragment 。

但是我得到了

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uday.honeytest/com.uday.honeytest.CheckList}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment

setContentView 行出错。

我的描述 fragment 类是:已编辑:

public static class Description extends Fragment {

View mConverView;
String details[];

public static Description getInstance() {
Description desc=new Description();
return desc;

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}


public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {


TextView textview=new TextView(getActivity());
textview.setLayoutParams(new LayoutParams(MarginLayoutParams.WRAP_CONTENT, MarginLayoutParams.WRAP_CONTENT));



return textview;
}
}

这里做错了什么??

谢谢

最佳答案

您的 Activity CheckList 应该扩展 FragmentActivity 。

关于android - 二进制 XML 文件第 9 行 : Error inflating class fragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7162403/

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