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 8926693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:02:07+00:00 2026-06-15T08:02:07+00:00

I am using a Map Activity which has a Fragment which hosts MAPS. All

  • 0

I am using a Map Activity which has a Fragment which hosts MAPS.

All this is inside a tab as shown below

enter image description here

Now every time I am in Maps Tab and go to Details Tab and come back I am getting the following error.

12-04 06:05:37.858: E/AndroidRuntime(20034): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

PlaceActivity.java

public class PlaceActivity extends SherlockFragmentActivity implements
        OnShareTargetSelectedListener {

     private static final String MAPS_KEY = "0rQAS47Cicu2t78I-QQ";
        FragmentManager fm = getSupportFragmentManager();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);  
        MapView mMapView = new MapView(PlaceActivity.this, MAPS_KEY);

        mMapView.setClickable(true);
        Exchanger.mMapView = mMapView;


        //setContentView(R.layout.activity_place);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        ActionBar.Tab tabDetails = actionBar.newTab();
        ActionBar.Tab tabMaps = actionBar.newTab();

        tabDetails.setText("Details");
        tabMaps.setText("Maps");

        tabDetails.setTabListener(new MyTabListener());
        tabMaps.setTabListener(new MyTabListener());

        actionBar.addTab(tabDetails);
        actionBar.addTab(tabMaps);
    }

    private class MyTabListener implements ActionBar.TabListener {
        @Override
        public void onTabSelected(Tab tab,
                android.support.v4.app.FragmentTransaction ft) {
            // TODO Auto-generated method stub
            if (tab.getPosition() == 0) {
                DetailsFragment fragment = new DetailsFragment();
                ft.replace(android.R.id.content, fragment);

            } else {

                fm.beginTransaction().add(android.R.id.content, MapSample.GeoGigMapFragment.newInstance()).commit();
                //MapsFragment fragment = new MapsFragment();
                //ft.replace(android.R.id.content, fragment);
                //ft.commit();
            }
        }

        @Override
        public void onTabUnselected(Tab tab,
                android.support.v4.app.FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTabReselected(Tab tab,
                android.support.v4.app.FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }

    }
.
.
.
.
.
}

My Maps Activity

MapSample.java

public class MapSample extends MapActivity {

    MapView mMapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
    }

    public static final class GeoGigMapFragment extends Fragment 
    {

        static GeoGigMapFragment newInstance() 
        {
            GeoGigMapFragment map = new GeoGigMapFragment();
            return map;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) 
        {
            MapView mMapView = Exchanger.mMapView;
            return mMapView;
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        // ((ViewGroup)mMapView.getParent()).removeView(mMapView);
        // mMapView.removeView(mMapView);

        // mMapView.removeAllViews();

        // ViewParent som = mMapView.getParent();
        // ((ViewGroup) som).removeView(mMapView);

        if (mMapView != null) 
        {
            // NoSaveStateFrameLayout parentView = (NoSaveStateFrameLayout)
            // mMapView.getParent();
            // parentView.removeView(mMapView);
            ((ViewGroup) mMapView.getParent()).removeAllViews();
        }

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

What I want to achieve is every time I click DetailsTab I want to destroy the MapSample or the Map View so that I don’t get the error.

Full Error Trace

12-04 06:26:38.808: E/AndroidRuntime(22066): FATAL EXCEPTION: main
12-04 06:26:38.808: E/AndroidRuntime(22066): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.view.ViewGroup.addView(ViewGroup.java:3210)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.view.ViewGroup.addView(ViewGroup.java:3155)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.view.ViewGroup.addView(ViewGroup.java:3131)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.support.v4.app.NoSaveStateFrameLayout.wrap(Unknown Source)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.support.v4.app.BackStackRecord.run(Unknown Source)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(Unknown Source)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.support.v4.app.FragmentManagerImpl$1.run(Unknown Source)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.os.Handler.handleCallback(Handler.java:725)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.os.Looper.loop(Looper.java:137)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at android.app.ActivityThread.main(ActivityThread.java:5039)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at java.lang.reflect.Method.invokeNative(Native Method)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at java.lang.reflect.Method.invoke(Method.java:511)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-04 06:26:38.808: E/AndroidRuntime(22066):    at dalvik.system.NativeStart.main(Native Method)
  • 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-06-15T08:02:08+00:00Added an answer on June 15, 2026 at 8:02 am

    on which line do you get the error?
    try to add

    contanier.removeAllViews();
    

    in the onCreateView method

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

Sidebar

Related Questions

Friends i am making an application in which i am using Map Activity. Now
I am using a demo for map view activity. There are no errors shown
Hello i'm using map() jquery to create a new object array DEMO but this
i want to integrate maps using map kit in iphone, and i am successful
I'm creating a map using Google Fusion Tables. It has several layers that are
I have made my own map using the google maps api. It is a
I am making an app in which i am using google map and my
I've a layout now, which has a add location button. The current layout is
I've got overlay icons all over my map activity that each need to pop
Using the com.google.android.maps API, I've got a MapActivity which uses ItemizedOverlay to place several

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.