Note that there are some explanatory texts on larger screens.

plurals
  1. POThe specified child already has a parent. You must call removeChild() on child's parent when populating a Table Row
    primarykey
    data
    text
    <p>Hello I have the following error when trying to add Views into a TableRow. I get the error message: "The specified child already has a parent. You must call removeChild() on child's parent" when the second View is added. Here is the code I'm using:</p> <pre><code>TableLayout table2 = new TableLayout(this); table2.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); for(int count = 0; count &lt; films.size() ; count++){ TableRow tableRow = new TableRow(this); Film film = films.get(count); count++; Film film2 = new Film(); if(count != films.size()){ film2 = films.get(count); count++; } tableRow.addView(flim.getPhoto()); if(!film2.getName().contentEquals("")){ //tableRow.addView(film2.getPhoto()); } table2.addView(tableRow); // Add the new row to our tableLayout } LinearLayout l2 = (LinearLayout)findViewById(R.id.root); l2.addView(table2); } </code></pre> <p>When I try to add the 2° film, I get the following exception:</p> <pre><code>?:??: W/?(?): FATAL EXCEPTION: main ?:??: W/?(?): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pipoca/com.vista.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. ?:??: W/?(?): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) ?:??: W/?(?): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) ?:??: W/?(?): at android.app.ActivityThread.access$600(ActivityThread.java:130) ?:??: W/?(?): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) ?:??: W/?(?): at android.os.Handler.dispatchMessage(Handler.java:99) ?:??: W/?(?): at android.os.Looper.loop(Looper.java:137) ?:??: W/?(?): at android.app.ActivityThread.main(ActivityThread.java:4745) ?:??: W/?(?): at java.lang.reflect.Method.invokeNative(Native Method) ?:??: W/?(?): at java.lang.reflect.Method.invoke(Method.java:511) ?:??: W/?(?): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) ?:??: W/?(?): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) ?:??: W/?(?): at dalvik.system.NativeStart.main(Native Method) ?:??: W/?(?): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. ?:??: W/?(?): at android.view.ViewGroup.addViewInner(ViewGroup.java:3378) ?:??: W/?(?): at android.view.ViewGroup.addView(ViewGroup.java:3249) ?:??: W/?(?): at android.view.ViewGroup.addView(ViewGroup.java:3194) ?:??: W/?(?): at android.view.ViewGroup.addView(ViewGroup.java:3170) ?:??: W/?(?): at com.vista.MainActivity.armarTabla(MainActivity.java:264) ?:??: W/?(?): at com.vista.MainActivity.onTabSelected(MainActivity.java:200) ?:??: W/?(?): at com.actionbarsherlock.internal.app.ActionBarWrapper$TabWrapper.onTabSelected(ActionBarWrapper.java:344) ?:??: W/?(?): at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:570) ?:??: W/?(?): at com.android.internal.app.ActionBarImpl.setSelectedNavigationItem(ActionBarImpl.java:356) ?:??: W/?(?): at com.android.internal.app.ActionBarImpl.setNavigationMode(ActionBarImpl.java:1158) ?:??: W/?(?): at com.actionbarsherlock.internal.app.ActionBarWrapper.setNavigationMode(ActionBarWrapper.java:204) ?:??: W/?(?): at com.vista.MainActivity.showTabsNav(MainActivity.java:190) ?:??: W/?(?): at com.vista.MainActivity.onCreate(MainActivity.java:63) ?:??: W/?(?): at android.app.Activity.performCreate(Activity.java:5008) ?:??: W/?(?): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) ?:??: W/?(?): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) ?:??: W/?(?): ... 11 more ?:??: W/?(?): [ 02-28 07:34:23.878 417: 2107 W/ActivityManager ] ?:??: W/?(?): Force finishing activity com.pipoca/com.vista.MainActivity ?:??: W/?(?): [ 02-28 07:34:24.378 417: 430 W/ActivityManager ] ?:??: W/?(?): Activity pause timeout for ActivityRecord{415eaff0 com.pipoca/com.vista.MainActivity} ?:??: W/?(?): [ 02-28 07:34:24.388 417: 430 D/WindowManager ] </code></pre> <p>Could anyone please tell what am I doing wrong? Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload