gpt4 book ai didi

android - 指定的子项已有父项。填充表格行时,您必须对 child 的 parent 调用 removeChild()

转载 作者:行者123 更新时间:2023-11-30 03:45:03 26 4
gpt4 key购买 nike

您好,我在尝试将 View 添加到 TableRow 时出现以下错误。当添加第二个 View 时,我收到错误消息:“指定的子项已有父项。您必须在子项的父项上调用 removeChild()”。这是我正在使用的代码:

TableLayout table2 = new TableLayout(this);
table2.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
TableLayout.LayoutParams.WRAP_CONTENT));

for(int count = 0; count < 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);
}

当我尝试添加 2° 胶片时,出现以下异常:

?:??: 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 ]

谁能告诉我我做错了什么?提前致谢

最佳答案

异常表明您的 getPhoto() 方法返回的 View (我想它是一个 ImageView)之前已经添加到父级。

只需使用您的 IDE 查找 getPhoto() 的所有用法,以确定发生这种情况的位置。

关于android - 指定的子项已有父项。填充表格行时,您必须对 child 的 parent 调用 removeChild(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com