Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么.addView会引发此父/子异常?_Java_Android_Layout_Android Studio - Fatal编程技术网

Java 为什么.addView会引发此父/子异常?

Java 为什么.addView会引发此父/子异常?,java,android,layout,android-studio,Java,Android,Layout,Android Studio,你好! 我试图在我的主要活动中的线性布局中创建动态文本视图。该程序(应该)根据需要将TextView从resultrowXML推出到activity\u fivethreeoneXML。 行parentLayout.addView(textView)正在抛出此错误 The specified child already has a parent. You must call removeView() on the child's parent first. 我尝试过类似问题的答案,但没有成功。

你好!
我试图在我的主要活动中的线性布局中创建动态文本视图。该程序(应该)根据需要将TextView从
resultrow
XML推出到
activity\u fivethreeone
XML。 行
parentLayout.addView(textView)正在抛出此错误

The specified child already has a parent. You must call removeView() on the child's parent first.
我尝试过类似问题的答案,但没有成功。



类别:

试试看{
LinearLayout parentLayout=(LinearLayout)findViewById(R.id.linLayout);
LayoutInflater LayoutInflater=getLayoutInflater();
视图;

对于(int counter=0;counter
textView
已作为父视图
查看
,事实上,您可以使用findViewById成功查找它。因此此行:

parentLayout.addView(textView);
正在导致异常。您可能希望将
视图
添加到
父布局

parentLayout.addView(view);

由于它刚刚创建,因此没有父对象,可以作为子对象添加它

您正在尝试添加一个已属于现有
视图组的
EditText

拆下线路

parentLayout.addView(textView);
从你的代码。你不需要这样做。替换为

parentLayout.addView(view);

谢谢!!我从下午4点(这里快到午夜了)就开始发抖了。非常感谢!我喜欢/讨厌这么小的东西!@jackEarlyDays:嘿,很抱歉回复这么晚……没问题,我们都是来互相帮助的。顺便说一句,我先回答了。我认为我的答案应该标记正确才公平:)嘿,不公平!!!我先回答!
parentLayout.addView(view);