The specified child already has a parent. You must call removeView() on the child's parent first.

报错:

The specified child already has a parent. You must call removeView() 
on the child's parent first.
我是在用Android第三方库SlideMenu的时候出现的错误 ,原来的代码是把supportFragmentManager得到的manager赋给一个字段,以后就直接调用这个字段。

错误代码

private FragmentManager supportFragmentManager;

supportFragmentManager = getSupportFragmentManager();
        supportFragmentManager.beginTransaction().replace(R.id.content_frame, new ContentFragment()).commit();
        setBehindContentView(R.layout.left_activity);

        supportFragmentManager.beginTransaction().replace(R.id.left_frame, new LeftFragment()).commit();

后来比对sample代码,发现不赋值字段就OK了
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new ContentFragment()).commit();


可是再验证再用字段时,发现又OK了。我有点晕了,你们且试试吧!如果仍旧出错,或你有什么好的解决方案就贴给我吧!

你可能感兴趣的:(Android)