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

  • Home
  • SEARCH
  • 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 8996597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:46:32+00:00 2026-06-15T23:46:32+00:00

I’m trying to use new android maps in my app. I’ve got a FragmentActivity

  • 0

I’m trying to use new android maps in my app.

I’ve got a FragmentActivity which layout contains (among other things):

<LinearLayout a:id="@+id/fragment_container"
    a:layout_width="fill_parent"
    a:layout_height="100dp"
    a:layout_weight="1"/>

It also has a button which changes this fragment using (mostly copied from sample project):

if (condition) {
    fragment = new Fragment1();
} else {
    fragment = new LocationFragment();
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();

and LocationFragment is:

public class LocationFragment extends SupportMapFragment{
private GoogleMap mMap;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    view = inflater.inflate(R.layout.map_fragment, container, false);
    setUpMapIfNeeded();
    return view;
}

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

private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment)  getActivity().getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            setUpMap();
        }
    }
}

private void setUpMap() {
    mMap.addMarker(new MarkerOptions().position(new LatLng(60.02532, 30.370552)).title(getString(R.string.map_current_location)));
}
}

xml layout is:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      class="com.google.android.gms.maps.SupportMapFragment"/>

The problem is that when we replacing fragment with LocationFragment for the second time android is unable to inflate from xml. It crashes on line:

view = inflater.inflate(R.layout.map_fragment, container, false);

with exception:

12-17 01:47:31.209: ERROR/AndroidRuntime(4679): FATAL EXCEPTION: main
    android.view.InflateException: Binary XML file line #4: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at my.package.LocationFragment.onCreateView(LocationFragment.java:29)
    ...

And I have no Idea how to solve it.
I think that it could be connected with an old issue that you cannot use more than one map view (found questions on android map v1).
But in case of v2 and fragments support it must be the way to replace fragment container with map fragment, am I right?

  • 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-15T23:46:33+00:00Added an answer on June 15, 2026 at 11:46 pm

    You are extending SupportMapFragment. That is perfectly fine, though I am uncertain how common that pattern will be (this is all a bit too new).

    However, SupportMapFragment is a fragment and knows how to display a map. You should not be overriding onCreateView() in most cases, and you certainly should not be overriding onCreateView() and trying to inflate a layout file that contains a <fragment> element pointing back to SupportMapFragment.

    Here is a sample app that uses SupportMapFragment from the Maps V2 library. The activity loads a layout that has SupportMapFragment:

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      class="com.google.android.gms.maps.SupportMapFragment"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am writing an app for my school newspaper, which is run completely online
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.