Java.lang.IllegalStateException: The specified child already has a parent. You must first call removeView () on the parent parent

This is my code:

Frame.gameController.test(); setContentView(Frame.world.getScreen()); Frame.world.setRunning(true); 

The following error appears on the second line:

 ERROR/AndroidRuntime(15229): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child parent first. 

Can someone help me solve this problem? It used to work very well, the problem starts when I accept this in another activity.

I am using android 2.2.

+7
source share
2 answers

You cannot use the same view in multiple actions. Instead, you should create a new instance of the view.

+10
source

Perhaps you are trying to install content from objects that already have a parent. It looks like you are installing some views in one action, for example:

 TextView tv = new TextView(); layout.adView(tv); layout2.adView(tv); 

and this error appears when you try to add this TV to a different format. In your situation, this is because the layout from one action is trying to be set as a child of another activity.

You must first release the child from another parent.

+11
source

All Articles