Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:41:54+00:00 2026-05-31T19:41:54+00:00

i am creating a new android application.i am using the table layout. I have

  • 0

i am creating a new android application.i am using the table layout. I have coded as follow but when i run the program it is shows force to close the program.
can any one help on this code .

public  class SongsActivity extends Activity{

    DemoView demoview ;
    DemoView2 finalview;
    DemoView3 dview;
    DemoView4 deview;

    ViewFlipper c ;
    TableLayout d;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.songs_layout);
        demoview = new DemoView(this);
        finalview = new DemoView2(this);
        dview= new DemoView3(this);
        deview = new DemoView4(this);
         d= new TableLayout(this);


        c=(ViewFlipper)findViewById(R.id.viewFlipper1);
        c.addView(demoview,0);
        c.addView(finalview, 1);
        c.addView(dview, 2);
        c.addView(deview, 3);
        c.setAutoStart(true);
        c.setFlipInterval(500);
        c.startFlipping();



        TableRow rw1=new TableRow(this);
         TableRow rw2=new TableRow(this);
         TableRow.LayoutParams params = new TableRow.LayoutParams();  
         params.span = 6;
        rw1.addView(c);
        rw2.addView(c);
        d.addView(rw2);
        d.addView(rw1);
        setContentView(d);
    } 

my layout defination is as follow

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

<TableRow
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
    android:id="@+id/tableRow1">

    <!-- Screen Design for the SONGS -->
<ViewFlipper android:id="@+id/viewFlipper1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >
  </ViewFlipper>

</TableRow>

<TableRow

  android:orientation="vertical"
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

</TableRow>
</TableLayout>

my logcat is showing following error

03-24 14:33:50.722: E/AndroidRuntime(322): FATAL EXCEPTION: main
03-24 14:33:50.722: E/AndroidRuntime(322): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidtablayout/com.example.androidtablayout.SongsActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.widget.TabHost.setCurrentTab(TabHost.java:323)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.view.View.performClick(View.java:2408)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.view.View$PerformClick.run(View.java:8816)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.os.Handler.handleCallback(Handler.java:587)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.os.Looper.loop(Looper.java:123)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.app.ActivityThread.main(ActivityThread.java:4627)
03-24 14:33:50.722: E/AndroidRuntime(322):  at java.lang.reflect.Method.invokeNative(Native Method)
03-24 14:33:50.722: E/AndroidRuntime(322):  at java.lang.reflect.Method.invoke(Method.java:521)
03-24 14:33:50.722: E/AndroidRuntime(322):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-24 14:33:50.722: E/AndroidRuntime(322):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-24 14:33:50.722: E/AndroidRuntime(322):  at dalvik.system.NativeStart.main(Native Method)
03-24 14:33:50.722: E/AndroidRuntime(322): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.view.ViewGroup.addView(ViewGroup.java:1865)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.view.ViewGroup.addView(ViewGroup.java:1822)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.view.ViewGroup.addView(ViewGroup.java:1802)
03-24 14:33:50.722: E/AndroidRuntime(322):  at com.example.androidtablayout.SongsActivity.onCreate(SongsActivity.java:51)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-24 14:33:50.722: E/AndroidRuntime(322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-24 14:33:50.722: E/AndroidRuntime(322):  ... 18 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:41:56+00:00Added an answer on May 31, 2026 at 7:41 pm

    The view flipper was added to first table row (rw1) and you are trying to add it again to the second table row (rw2). That’s why you get an error.
    This view already has a parent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an Android application, and I have a problem.(I am new to
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I am new to android. I just created a simple application using Aynctask. Basically,
I'm creating an android application in which i will need to store data using
While creating a new android project in eclipse 3.5, i have selected Android 2.1
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
I need UNION two tables with creating new field, where 1 for first table,
I have 2 custom fields in my WordPress system when creating new posts. One
I have some conditional formatting styles. I don't want to keep creating new rules
I have such view that handles user registration. After creating new user i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.