Question

I'm trying to create a mapFragment inside a view flipper. I have tried several approaches to it and cannot get it to work. so far I have tried:

  • Declaring the fragment in the right part of the view flipper and accessing it there. The problem with this is that the view isn't loaded until it is switched into so the map doesn't exist and it creates a null pointer error when I try to access it.
  • My second approach was declaring a map fragment progromatically and then inserting it into a FrameLayout container using fragment transactions.
  • The third thing I tried was loading a fragment from an external file and inserting it into the container using a fragment transaction.

All of these were tried in the onCreateand the call that caused them to throw a null pointer exception was inside the onResume method. I would appreciate it if anyone has experienced this behavior before and knows how to fix it.

Was it helpful?

Solution

As You are extending FragmentActivity, indicating that you are trying to use the Android Support package backport of fragments. However, your element refers to MapFragment, which is for the nativeAPI Level 11` edition of fragments.

Replace MapFragment with SupportMapFragment, and that should clear up this specific crash

if that also doesnt solve Then you have a problem with your API key or something. Check LogCat for messages
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top