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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:16:36+00:00 2026-06-15T16:16:36+00:00

I am creating an app which has action bar and 2 tabs. like this:

  • 0

I am creating an app which has action bar and 2 tabs. like this:enter image description here

Tab1: on click should display some details of a place.
Tab2: on click should display maps.

I am using Fragments for this.

My tablistener:

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 {
                MapsFragment fragment = new MapsFragment();
                ft.replace(android.R.id.content, fragment);
                //ft.commit();
            }
        }

MapsFragment.java

public class MapsFragment extends MapFragment {

    private MapView map = null;
    private MyLocationOverlay me = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return (new FrameLayout(getActivity()));
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        map = new MapView(getActivity(),
                "0rQAS47Cicu2t7z4w8Ev6A6de7QlbjvKyi8I-QQ");
        map.setClickable(true);

        map.getController().setCenter(
                getPoint(40.76793169992044, -73.98180484771729));
        map.getController().setZoom(17);
        map.setBuiltInZoomControls(true);

        Drawable marker = getResources().getDrawable(R.drawable.marker);

        marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                marker.getIntrinsicHeight());

        map.getOverlays().add(new SitesOverlay(marker));

        me = new MyLocationOverlay(getActivity(), map);
        map.getOverlays().add(me);

        ((ViewGroup) getView()).addView(map);
    }

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

        me.enableCompass();
    }

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

        me.disableCompass();
    }

    private GeoPoint getPoint(double lat, double lon) {
        return (new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0)));
    }

    private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
        private List<OverlayItem> items = new ArrayList<OverlayItem>();

        public SitesOverlay(Drawable marker) {
            super(marker);

            boundCenterBottom(marker);

            items.add(new OverlayItem(getPoint(40.748963847316034,
                    -73.96807193756104), "UN", "United Nations"));
            items.add(new OverlayItem(getPoint(40.76866299974387,
                    -73.98268461227417), "Lincoln Center",
                    "Home of Jazz at Lincoln Center"));
            items.add(new OverlayItem(getPoint(40.765136435316755,
                    -73.97989511489868), "Carnegie Hall",
                    "Where you go with practice, practice, practice"));
            items.add(new OverlayItem(getPoint(40.70686417491799,
                    -74.01572942733765), "The Downtown Club",
                    "Original home of the Heisman Trophy"));

            populate();
        }

        @Override
        protected OverlayItem createItem(int i) {
            return (items.get(i));
        }

        @Override
        protected boolean onTap(int i) {
            Toast.makeText(getActivity(), items.get(i).getSnippet(),
                    Toast.LENGTH_SHORT).show();

            return (true);
        }

        @Override
        public int size() {
            return (items.size());
        }
    }
}

The problem is when i click on maps tab for the first time map appears. but wen i go to details tab and again come back to maps tab, my app crashes with an error:

Logcat:

12-04 03:28:02.228: E/AndroidRuntime(14466): FATAL EXCEPTION: main
12-04 03:28:02.228: E/AndroidRuntime(14466): java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
12-04 03:28:02.228: E/AndroidRuntime(14466):    at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:398)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at com.google.android.maps.MapView.<init>(MapView.java:289)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at com.google.android.maps.MapView.<init>(MapView.java:235)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at com.m7.nomad.MapsFragment.onCreate(MapsFragment.java:34)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.support.v4.app.BackStackRecord.run(Unknown Source)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(Unknown Source)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.support.v4.app.FragmentManagerImpl$1.run(Unknown Source)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.os.Handler.handleCallback(Handler.java:725)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.os.Looper.loop(Looper.java:137)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at android.app.ActivityThread.main(ActivityThread.java:5039)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at java.lang.reflect.Method.invokeNative(Native Method)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at java.lang.reflect.Method.invoke(Method.java:511)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-04 03:28:02.228: E/AndroidRuntime(14466):    at dalvik.system.NativeStart.main(Native Method)

What is the problem. I know that MapView cant be inflated from fragment. But i used this technique:
http://xrigau.wordpress.com/2012/03/22/howto-actionbarsherlock-mapfragment-listfragment/

But still this doesn’t work. I need some Help.

  • 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-15T16:16:37+00:00Added an answer on June 15, 2026 at 4:16 pm

    Just some days ago Google has introduced Map Api 2. And it containts MapFragment. So now you don’t need such hooks.
    https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

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

Sidebar

Related Questions

I am creating an app which has around 15 different animations. Some animations are
I'm creating an Android app which must do some web surfing in the background
I'm creating a Facebook app in which I want to display content depending on
i am creating an app which has two UIImageViews at top and bottom of
I'm creating a Django app in which I have a table which has 'items',
I'm creating C# winforms app which has to find all occurences of a string
I'm creating an app which has the ability for the user to pin a
I wrote a little app, which has some locales and language options. When user
I am creating an app in Backbone.js which has a parent and multiple child
I'm creating an app on android in java, very simple, which has a button

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.