加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Android中error inflating class fragment

(2013-07-16 10:11:21)
标签:

it


在Activity中静态使用fragment的时候,要注意两个地方。

Fragment引用的包是:

import android.support.v4.app.Fragment;
而不是:

import android.app.Fragment;

然后Activity必须是继承FragmentActivity
import android.support.v4.app.FragmentActivity;

不然就会出现这个错误。


【Android异常】The specified child already has a parent. You must call removeView() on the child's parent first.

 

 

错误信息: 

Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

 

信息补充:

使用FragmentActvitiy + Fragment

 

错误原因:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflater.inflate(R.layout.preference_fragment, container);

 

解决办法: 

View v = inflater.inflate(R.layout.preference_fragment, containerfalse);

 

补充信息:

导致此错误并不一定就是这个原因,大家也能搜到很多其他的原因,这里备注一下。 

之前使用ActionBar里面的Fragment好像是可以的。 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有