I am trying to implement maps and I am getting error of Inconvertible types; cannot cast android.support.v4.app.Fragment to com.google.android.gms.maps.SupportMapFragment
I have seen some resources but nothing works for me
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
Inconvertible types; cannot cast 'android.support.v4.app.Fragment' to 'com.google.android.gms.maps.SupportMapFragment'
As per the Google Play services Android release notes for play-services-maps:17.0.0:
Warning: This release is a MAJOR version update and breaking change.
- Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.
Maps 17.0.0 has switched to AndroidX. That means that SupportMapFragment now extends androidx.fragment.app.Fragment, not the Support Library equivalent. You need to either switch back to 16.1.0 or migrate your app to AndroidX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With