07-23 11:03:59.844: E/AndroidRuntime(16235):
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
07-23 11:10:05.749: E/AndroidRuntime(16662): at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
在用Fragment 的时候遇到这个bug
FragmentManager fm =getSupportFragmentManager();
FragmentTransaction fg = fm.beginTransaction();
fg.replace(R.id.viewer, new VagetableFragment());
fg.commit();
找了半天原来以为是fragment 的布局问题
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/viewer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
但是怎么试还是报这个错误,看到logcat里面有一行
07-23 11:10:05.749: E/AndroidRuntime(16662): at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
后来怀疑是不是fragment写错误,这个fragment很简单,就一个布局的加载
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_vagetablemarket,
container);
return rootView;
}
细细一看少了一个参数啊,正确的应该是
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_vagetablemarket,
container, false);
return rootView;
}
问题解决