二进制XML文件行#9:错误充气类片段
正在逐渐错误inflating fragment error while running calling an Activity which having fragments.
二进制XML文件行#9:错误充气类片段
检查表是包含listview and Description fragments.
及其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>
核对表类是:
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;
}
}
同样我有这个下面的描述片段。
但正在逐渐的setContentView线
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
错误。
和我描述段类:编辑:
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;
}
}
我究竟做错了什么?
感谢
<fragment class="com.uday.honeytest.CheckList$Description"
就是它越来越错误。
您确定您具有完全合格的类名正确键入?
您是否尝试过清理项目/修复项目属性?
我没有看到任何名称为Description
的类,这可能是问题。
希望这会有所帮助。
我刚刚删除onCreateView
代码which contains inflating xml
在listview fragment
并转入onActivityCreated
方法与它的工作。
The reason may be:
ListFragment具有由单个列表视图组成的默认布局。但是,如果您愿意,您可以通过从onCreateView(LayoutInflater,ViewGroup,Bundle)返回自己的视图层次来自定义片段布局。要做到这一点,你的视图层次结构必须包含一个ID为“@android:id/list”的ListView对象(或者列表如果它在代码中)
所以我的listview继承了ListFragment而不是xml中的conatining列表,直接我们可以在onActivityCreated中而不是在onCreateView中设置ListListAdapter。
您可能没有必要这样做。我在你的例子中注意到你的onCreateView方法上面没有@Override指令。它被召唤了吗? –
这是有点误导,因为你一定已经走了@ spin.goran的回答 – Prateek
你应该真的发布你的描述类代码。 – RoflcoptrException
检查我的描述片段类编辑:这是在CheckList活动只。 – Udaykiran
我从这里试过这个例子:http://www.vogella.com/articles/Android/article.html#fragments 和我有2个问题: - 我需要使用'android.support.v4.app '而不是'android.app.Fragment'因为我在API级别8(Android在Android 3.0(API级别11)中引入了片段) - android:layout_marginTop =“android:attr/actionBarSize”与API级别8不兼容 - 请参阅http:// stackoverflow。com/questions/7760817/how-to-get-androidattr-actionbarsize-with-compatibility-library – Paul