2013-05-13 4 views
0

무슨 일이 일어나고 있는지 모르겠습니다. 내 코드가 충돌하고 이유를 찾지 못합니다.지정된 자식에는 이미 부모가 있습니다.

저는 여러 WebViews의 컨테이너 인 LinearLayout을 가졌습니다.

LinearLayout variableContent = (LinearLayout) this.findViewById(R.id.variableContent); 
for (int i=0; i<5;i++){ 
    XMLModule modul = modulsRecuperats.get(i); 
    myWebView webview = new myWebView(this); 
    WebView customWebViewContainer = (WebView) this.mInflater.inflate(R.layout.customwebview, null); 
    customWebViewContainer = webview._clientSettings(customWebViewContainer,progressDialog); 
    customWebViewContainer.loadData(modul.getContent(), "text/html", "UTF-8"); 
    variableContent.addView(customWebViewContainer); 
} 

addView를 호출하면 코드가 충돌합니다. 이 오류 :

Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

이유를 찾을 수 없습니다. 너 나 좀 도와 줄 수있어?

+0

variableContent에 이미 일부 콘텐츠가있는 것으로 보입니다. variableContent.removeView()를 수행 한 다음 for 루프를 호출 할 수 있습니다. – lokoko

+0

하지만 선형 레이아웃은 여러 개의 하위를 포함 할 수있는 레이아웃이기 때문에 의미가 없습니다 ... – Reinherd

답변

1

문제는 customWebViewContainer에 이미 상위 항목이 있다는 것입니다. View에는 부모가 2 명일 수 없으므로이 예외가 throw됩니다. 나는 webview._clientSettings()에 대한 호출이 다른 컨테이너와 함께 해당 뷰를 래핑한다고 가정 할 수 있습니다.

0

"myWebView"클래스를 게시 하시겠습니까? 특히 _clientSettings 메서드가 필요하므로 거기에서 무슨 일이 일어나는지 알 수 있습니다.

관련 문제