어제 나는 안드로이드 용 책상 시계를 만들었습니다. 이것을 위해 RelativeLayout을 만들어 시간, 분 등을 표시하고 옵션 정보 및 종료를 표시하는 메뉴를 만들었습니다. 글쎄, 모두 정상적으로 작동하지만 옵션을 클릭하면 문제가 발생합니다. 로그 캣이 보여줍니다어버이의 부모에게 removeView()를 호출합니다.
그래서 나는 당신이 날 도울 수 있기를 바랍니다E/AndroidRuntime(14751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iamaner.T2Speech/com.iamaner.T2Speech.FrmAbout}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
... 필자가이 코드에 대해 들어,하지만 난 그것을 넣어하는 방법과 위치를 잘 모릅니다, 나는이 확인 될 것이라고 생각하지만
여기 final RelativeLayout fondo = (RelativeLayout)findViewById(R.id.your_layout);((RelativeLayout)fondo.getParent()).removeView(fondo); //scrollView.removeView(scrollChildLayout);
는 매니페스트 파일 내가 그 문제를 생각한다없는 것 같다, 내가 여기 FrmAbout 코드
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TimeToSpeechActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FrmAbout" />
</application>
을 그리고 : 잘 모릅니다
public class FrmAbout extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frmabout);
TextView txtVersion = (TextView)findViewById(R.id.Txtversion);
TextView txtWarning = (TextView)findViewById(R.id.Txtwarning);
TextView txtInstructions = (TextView)findViewById(R.id.Txtinstructions);
TextView txtContact = (TextView)findViewById(R.id.Txtcontact);
setContentView(txtVersion);
setContentView(txtWarning);
setContentView(txtInstructions);
setContentView(txtContact);
}
}
좋아, 그것을 해결 .... 문제가 있었다 된 setContentView() 메소드를, 그것을 삭제하고 지금은 작동
시도해보십시오. ((ViewGroup) scrollChildLayout.getParent()). removeallViews();이 답변에서 제안했습니다. http://stackoverflow.com/questions/6526874/call-removeview-on-the-childs-parent-first –