昨天我为安卓创建了一个台钟。为此,我创建了一个 RelativeLayout 来显示小时、分钟等......和一个菜单来显示关于和退出选项......嗯,一切正常,但是当我点击关于选项时问题出现了:它强制关闭和LogCat 显示了这一点:
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);
这是我认为是问题的清单文件,我不知道:
<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>
在这里,FrmAbout 代码:
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() 方法,删除它,现在它可以工作了