一、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
未完,待續。。。。