I am trying to display a map in frame layout but it keeps crashing with the error 'attempt to invoke virtual method com.google.android.gms.maps.supportmapfragment. Getmapasynctask come. Google. Android. Gms.maps.onreadycallback on null object reference'. Below is my main activity code
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_standardkuta);
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapee);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap=googleMap;
LatLng Kuta=new LatLng(12,28);
mMap.addMarker(new MarkerOptions().position(Kuta).title("kk"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(Kuta));
}
}
I did research and found this findFragmentById for SupportMapFragment returns null in Android Studio sadly the solution requires I change getsupporfragmentmanager to getchildfragmentmanager, when I attempted this I received an error cannot resolve symbol getchildfragmentmanager. Below is my xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Standardkuta">
<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="120dp"
android:layout_marginRight="120dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<fragment
android:id="@+id/mapee"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Please help