Skip to content Skip to sidebar Skip to footer

Android: Java.lang.IllegalStateException: The Specified Child Already Has A Parent. You Must Call RemoveView() On The Child's Parent First.

I am mking an android app in which i am making dynamically table rows and then adding imageviews and textviews to it dynamically. It adds the first row and then give the following

Solution 1:

The iv variable that you are adding, is not been created inside the loop so I imagine is created before... but in the second loop it's added to two different Table Rows.


Solution 2:

tr.addView(iv,0);

Problem is with the ImageView (iv), i think, since it is not instantiated inside the loop, so first time it was added to a row, and when you add it again to another row, it doesn't permit, because a view can have only 1 parent.

so i would suggest you to create a new ImageView for every time you loop.


Solution 3:

because you are adding same View with new value in each iteration .

initialize imageView iv ,before tr.addView(iv,0);

ImageView in = new ImageView(ctx)

Post a Comment for "Android: Java.lang.IllegalStateException: The Specified Child Already Has A Parent. You Must Call RemoveView() On The Child's Parent First."