Unable Instantiate Android.Gms.Maps.Mapfragment

Unable to instantiate android.gms.maps.SupportMapFragment

Judging by you error:

Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment:
make sure class name exists, is public, and has an empty constructor that is public

and the fact the SupportManFragment class is part of the google-play-services library, you problem is surtenly in the way you reference this library or the library it self.

I would suggest you to re-download it using the SDK-Manager and move it to a location where it path would be shorter and then try to reference it again using the answer you have in this question:

Error java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in Google Map V2

Unable to instantiate fragment com.google.android.gms.maps.MapFragment in Activity

I spend few days.but can't resolve this issue in Eclipse tool.Then I tried with Android studio.

Map is working fine.Issue has been resolved only in studio.In eclipse many times google map library issue happened to me.But when I moved to studio, my code is working fine.

Error occurred due to changes in new OS changed with eclipse tool and sdk.It might be google map library issue.

Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment after migration of androidX

You have to use a SupportMapFragment migrated from Android Support Libraries to AndroidX Libraries.

In you case use this version or later.

com.google.android.gms:play-services-maps:17.0.0

If you check the doc it extends androidx.fragment.app.Fragment.

Could Not Find Class com.google.android.gms.maps.SupportMapFragment


  • I do not see you mention adding the Android support library android-support-v4.jar. You need to make sure Eclipse is properly including it for com.google.android.gms.maps.SupportMapFragment to work:

    Eclipse Android project included libraries path

  • Another potential issue is mismatch of play services library in your app and the play services verion on your nexus 5 device. If you downloaded the latest library from SDK manager, it may be higher version than the one on your device. I am guessing your play services version on device is 5.0.89, you can check on device Settings -> Apps -> Downloaded -> Google Play Services. Try using older version of the library if that's the case.

Finding Google Play Services version

Error using Map in app - com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment

Have you also changed the map in your XML layout?

Should look like this:

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


Related Topics



Leave a reply



Submit