Em 얻기 java.lang.IllegalStateException 발생 : 지정된 자식에 이미 상위가 있습니다. 먼저 부모의 부모에 대해 removeView()를 호출해야합니다.Java 비정상 상태 가져 오기 XML을 확장하여보기를 추가 할 때 예외가 발생했습니다.
어떤보기를 제거해야하는지 알 수 없으면 도움이 될 것입니다. 여기
는 코드 스 니펫입니다main.xml에
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/mainLayout"
android:layout_height="fill_parent"
android:orientation="vertical" >
</RelativeLayout>
인 data.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</RelativeLayout>
활동 코드
public class ToDo extends Activity {
/** Called when the activity is first created. */
Button addNew;
RelativeLayout mainLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainLayout=(RelativeLayout)findViewById(R.id.mainLayout);
RelativeLayout rel;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int idx=0;idx<2;idx++){
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rel = (RelativeLayout) inflater.inflate(R.layout.data,null);
params.setMargins(0, 50, 0, 0);
TextView fromWeb= (TextView) rel.findViewById(R.id.txt);
fromWeb.setText("AA");
mainLayout.addView(rel,params);
}
}
}
확인이 링크를 : http://stackoverflow.com/questions/10007094/java-lang-illegalstateexception-the-specified-child-already-has-a-parent –
시도하고 확인하자! – Badrinath