0

yesterday i created a Desk clock for android. For this I created a RelativeLayout to show Hours,minutes,etc... and a menu to show the options About, and Exit...Well, all works fine, but the problem comes when I click About Option: it force Closes and LogCat shows this:

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.

So I hope you can help me... Ive heard about this code, but i dont know where to put it,and how, i thought this would be Ok but it seems not

final RelativeLayout fondo = (RelativeLayout)findViewById(R.id.your_layout);((RelativeLayout)fondo.getParent()).removeView(fondo); //scrollView.removeView(scrollChildLayout);

Here is the manifest file i think its the problem, i dont know:

    <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>

And here, the FrmAbout code:

 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);

     }
     }

Ok, solved it.... the problem was the setcontentview() method, deleted it and now it works

BamsBamx
  • 4,139
  • 4
  • 38
  • 63
  • 1
    try this:((ViewGroup)scrollChildLayout.getParent()).removeallViews();its suggested in this answer. http://stackoverflow.com/questions/6526874/call-removeview-on-the-childs-parent-first – mayank_droid May 01 '12 at 11:22

1 Answers1

0

From your code i didn't understood Why you removing all views before calling About activity? Is this any of your requirement because to start new activity all the views need not be removed.. You can directly call startActivity(intent) without removing views from current activity.

Please post logs to help understand the problem.

Veer
  • 2,071
  • 19
  • 24
  • Ok, edited and added logcat error.. i did this because logcat says that i have to call removeView() before starting FrmAbout... – BamsBamx May 01 '12 at 11:48