I implemented an action that adds MapFragment at runtime. MapFragment xml contains a static fragment and I'm trying to add it at runtime. I also found that Lollipop has some problems adding a map fragment at runtime. Please check. Problem raised and workaround.
I also gave my codes below,
fragment_map.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".fragment.MapsFragment"> <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="appCreators.bloodfinder.activity.MapsActivity"/> <include android:id="@+id/layout" layout="@layout/template_custom_spinner"/> </FrameLayout>
MapsFragment.java
Implements onMapReadyCallback
public class MapsFragment extends SupportMapFragment implements OnMapReadyCallback
In onResume
@Override public void onResume() { super.onResume(); ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMapAsync(this); }
it always returns me to zero, and I also tried,
((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(this);
it also returns a NullPointerException
MapsActivity.java
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, MapsFragment.newInstance()).commit();
I add this to the onCreate Activity callback method.
I cannot understand why I am still getting a NullPointerException !
Sometimes I get Attempt to invoke interface method 'void com.google.maps.api.android.lib6.e.fl.o()' on a null object reference
Help will be appreciated!
UPDATE: Still not fixed, I get the following error. I looked into the magazines, but had no idea why this was happening.
Unable to resume activity {MapsActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.maps.api.android.lib6.e.fl.o()' on a null object reference
android nullpointerexception android-fragments supportmapfragment mapactivity
Kavin prabhu
source share