in Android development, I addView another layout view in one view (this view is obtained through inflate loading, where root is null, that is, there is no attached parent view). Why do I still report an error:
The specified child already has a parent. You must call removeView () on the child"s parent first.
the related code is as follows:
fragment.class:
<TextView
android:id="@+id/textView_up"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:id="@+id/textView_down"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
the error is as follows:
java.lang.RuntimeException: Unable to start activity ComponentInfo.classschedule.view.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child"s parent first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)