2013-05-13 151 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方法,以便我们知道那里发生了什么。

相关问题