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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:56:09+00:00 2026-06-18T06:56:09+00:00

Managed to get the codes error free, however upon launching, I somehow always get

  • 0

Managed to get the codes error free, however upon launching, I somehow always get a null pointer exception at the line mMap = mapFrag.getMap();

Why is this so? Am I missing some imports or some steps? I am unsure if it’s the SupportMapFragment or GoogleMap object that’s causing the problem.

package com.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MapFragment extends SherlockMapFragment {

    private GoogleMap mMap;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = super.onCreateView(inflater, container, savedInstanceState);
        SupportMapFragment mapFrag= (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_map);
        mMap = mapFrag.getMap(); //null pointer is here
        return root;
    }
}

Edit: This is part of the implementation based on the solution given in this question here

  • 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-18T06:56:10+00:00Added an answer on June 18, 2026 at 6:56 am

    Note that you do not need to use a custom Fragment subclass necessarily to use Maps V2. If your fragment is just purely a map, you can create the MapFragment or SupportMapFragment from the activity and configure it there.

    You do not even need to create some sort of SherlockMapFragment to be able to have a map be part of an ActionBarSherlock-based app. The regular SupportMapFragment works just fine.

    If you do want to have more business smarts in your fragment, and if you are using ActionBarSherlock, and the business logic in question needs to do things related to ActionBarSherlock (e.g., contribute action items to the action bar), then and only then do you need to worry about having some sort of SherlockMapFragment.

    I can confirm that this gist contains a working SherlockMapFragment. Note that it goes into the com.actionbarsherlock.app package, as it needs some package-protected access to the rest of ActionBarSherlock.

    You can then subclass that, such as creating a MyMapFragment:

    public class MyMapFragment extends SherlockMapFragment {
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    
        if (getMap() != null) {
          Log.d(getClass().getSimpleName(), "Map ready for use!");
        }
      }
    }
    

    You have to be a bit careful on the timing of calling getMap() — too soon and it will return null. onActivityCreated() seems like a fairly safe time, though you are free to experiment.

    Then, you just use MyMapFragment wherever you would have used 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.commonsware.android.mapsv2.sherlock.MyMapFragment"/>
    

    Here is the complete project containing the above code.

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

Sidebar

Related Questions

I managed to get this code to compile with out error. But somehow it
I managed to get some help from a previous question and I have the
I managed to get the YUI calendar widget working fine. But When it displays
I managed to get a unsigned long int octets-representation (BE) by reading IPv4 methods,
I managed to get authentication to work by following the tutorial from this page
I managed to get custom themes running for Tabs but still got a lil
I've managed to get both an iPad and iPhone hooked up to xcode, and
So I managed to get a page with Ajax ui.tab and in one of
I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
I get the below exception when I try to add/insert/remove to a collection (or

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.