2013-05-13 102 views
0

我不知道發生了什麼。我的代碼崩潰了,我找不到原因。指定的孩子已經有父母

我有一個LinearLayout,它是幾個WebView的容器。

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 2013-05-13 07:37:34

+0

但這沒有意義,因爲線性佈局是可以包含多個孩子的佈局...... – Reinherd 2013-05-13 07:40:11

回答

1

問題是customWebViewContainer已經有父項。 A View不能有2個父母,所以拋出這個異常。我只能假設對webview._clientSettings()的調用正在用另一個容器包裝該視圖。

0

請問您可以發佈「myWebView」類嗎?特別是需要_clientSettings方法,以便我們知道那裏發生了什麼。

相關問題