14

I'm currently implementing my own subclass of SupportMapFragment, using the google-play-services library r3.

I get a NullPointerException in one of the internal classes of the library when I try to add my Fragment to an Activity or ViewPager. Here's the relevant stacktrace:

java.lang.NullPointerException
    at maps.y.p.onResume(Unknown Source)
    at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:115)
    at android.os.Binder.transact(Binder.java:310)
    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onResume(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment$a.onResume(Unknown Source)
    at com.google.android.gms.internal.c$1.a(Unknown Source)
    at com.google.android.gms.internal.c.a(Unknown Source)
    at com.google.android.gms.internal.c.onResume(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment.onResume(Unknown Source)
    at android.support.v4.app.Fragment.performResume(Fragment.java:1503)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
    at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:807)
    at android.support.v4.app.FragmentManagerImpl.startPendingDeferredFragments(FragmentManager.java:1112)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1461)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)

Apparently the internal map is null at this point.

Did anyone already run into this issue and has a solution?

ligi
  • 39,001
  • 44
  • 144
  • 244
Ben Weiss
  • 17,182
  • 6
  • 67
  • 87

2 Answers2

33

In your subclass of SupportMapFragment, did you override onCreateView(...)?

If you did, you'd need to also call super.onCreateView(...) in your own onCreateView(...) to let the super class to create its view. The fragment is tied closely with the underlying view.

davidw
  • 376
  • 2
  • 2
  • You're right. A super call was missing. Adding it solved my NPE. Thanks! – Ben Weiss Dec 07 '12 at 21:24
  • @Keyboardsurfer i am trying to something similar. can you share some skeleton structure of how to do it ? http://stackoverflow.com/questions/13764266/android-supportmapfragment-exception-error – Harsha M V Dec 09 '12 at 20:51
  • Hi what if I don't want to call the super.onCreateView()? I'm trying to this instead with OSM tiles, is it possible? http://stackoverflow.com/questions/14984617/nulpointerexception-on-implementing-fragments-for-osmdroid – lyk Feb 21 '13 at 04:10
1

Try getChildFragmentManger() Also make sure you populate in or after onActivityCreated()


The Docs also seem to suggest that if the underlying Maps System is not running it will not work.

Also check you are using v11 of ACL (although I doubt thats the issue).

Chris.Jenkins
  • 13,051
  • 4
  • 60
  • 61
  • Thanks. But I'm not trying to place a SupportMapFragment inside my Fragment. I'm trying to actually subclass the SupportMapFragment. Also I'm using the ACL v11 and have taken care of the potential null return value of getMap. – Ben Weiss Dec 06 '12 at 09:24