一、Caused by:Java.lang.IllegalStateException: The specified child already has a parent.
造成这个原因,是组件在父类中重复加载了相同的组件
例如:
- TextView mTextView = new TextView(this);
- mTextView.setText("hello world");
- LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- // 第一次添加
- mLinearLayout.addView(mTextView, mLayoutParams);
- // 第二次添加
- mLinearLayout.addView(mTextView, mLayoutParams);
TextView mTextView = new TextView(this);
mTextView.setText("hello world");
LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
// 第一次添加
mLinearLayout.addView(mTextView, mLayoutParams);
// 第二次添加
mLinearLayout.addView(mTextView, mLayoutParams);
这样的话,我们重复添加了两次mTextView。这个是不允许的,在父类布局中,只能有唯一的对象,不能重复。
如果你想建立两个相同的组件,还是费力一下,再创建一个对象吧。o(╯□╰)o
未完,待续。。。。