user3740532
user3740532

Reputation: 13

Unable to cast Fragment to SupportMapFragment

why is it i could not cast the Fragment to SupportMapFragment.here is the code

 googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

here is my activity_main.xml

<fragment
   class="com.google.android.gms.maps.SupportMapFragment"
   android:id="@+id/map"
   android:layout_width="match_parent"
   android:layout_height="match_parent"/>

Upvotes: 0

Views: 180

Answers (1)

Illegal Argument
Illegal Argument

Reputation: 10358

It should be getSupportFragmentManager(). Make sure that your Activity extends FragmentActivity for ActionBarActivity from the support package.

googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
            R.id.map)).getMap();

Upvotes: 2

Related Questions