microacup / microacup.github.com

长者的经验
0 stars 1 forks source link

Android遇到The specified child already has a parent错误 #29

Open microacup opened 10 years ago

microacup commented 10 years ago

错误描述:

07-27 17:27:50.453: E/AndroidRuntime(1528): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

解决方案:

问题原因:

类似案例:

LinearLayout listMachines = (LinearLayout) findViewById(R.id.water_level_page_water_level_setting);
 LayoutInflater inflater = LayoutInflater.from(WaterLevelActivity.this);
View tlWaterLevelInfo = inflater.inflate(R.layout.unit_time_water_level_item, null);
listMachines.addView(tlWaterLevelInfo);
listMachines.addView(tlWaterLevelInfo);        //这个地方出错了。