0

I am trying to set the Google Map in an Android Studio Project but facing incompatible types error even after applying different options couldn't get rid of it. Thanks for your time and guidance

Screenshot of error

enter image description here

Logcate report

Error:(454, 88) error: incompatible types: Fragment cannot be converted to SupportMapFragment

XML code

<fragment
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/map2"
            class="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

Activity code

public class Search extends FragmentActivity implements OnMapReadyCallback

private void initializeMap()
{

   SupportMapFragment map = ((SupportMapFragment)     getFragmentManager().findFragmentById(R.id.map2)).getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {

}
shehzy
  • 2,215
  • 3
  • 25
  • 45

1 Answers1

0

try to change this line

SupportMapFragment map = ((SupportMapFragment)getFragmentManager().findFragmentById(R.id.map2)).getMapAsync(this);

to

SupportMapFragment map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map2)).getMapAsync(this);

For more information, check this SO question

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31