“Error inflating class fragment” with google map

前端 未结 10 1848
有刺的猬
有刺的猬 2020-12-01 09:29

I tried to make a sample project using Google Map, but I couldn\'t. Help me please!

Test Device : Android 4.0.4


Error Message :

12-2         


        
相关标签:
10条回答
  • 2020-12-01 10:24

    This problem also occurs when it is not able to inflate the Fragment class mentioned in the activity_main.xml(or the XML file present under res/layout), due to a SDK version incompatibility in the andriod_manifest.xml file.

    The correct versions for SDK levels to get the map on an emulator is this:

         <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="21" />
    
    0 讨论(0)
  • 2020-12-01 10:29

    I had the same problem and I did the mistake to only add one of the 2 following tags. Note that you are also missing one of these two

            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="<YOUR VALUE>"/>
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
    

    The actual error is really misleading, as you might be thinking of some API level UI issue.

    0 讨论(0)
  • 2020-12-01 10:29
    1. Do u have valid Google Map API key?
    2. try using

      public class MainActivity extends MapActivity{
       ... }
      
    0 讨论(0)
  • 2020-12-01 10:33

    Accepted answer is correct but meaningful information i share with you, may be anyone facing same issue what i face

    If everything is woking same as google code then please check manifest file in my case i added geo key and map key that's why exception occurs,

    Note - do not add two keys in manifest file remove map key

    meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/google_maps_key"/>
    

    above code and add this code.

     <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/auto_location"/>
    
     <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
    
    0 讨论(0)
提交回复
热议问题