“Error inflating class fragment” with google map

前端 未结 10 1847
有刺的猬
有刺的猬 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:07

    This defect has been resolved in play services library v9.0.0. https://code.google.com/p/gmaps-api-issues/issues/detail?id=9021#makechanges

    0 讨论(0)
  • 2020-12-01 10:09

    In my case, I had to do two corrections to make this exception go away.

    1. The activity should extend FragmentActivity and not Activity
    2. Manifest file needs a uses-permission for ACCESS_NETWORK_STATE (my file already had INTERNET permission)
    0 讨论(0)
  • 2020-12-01 10:18

    Some times you are using both -

    <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="<YOUR VALUE>"
    />
    <meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="<YOUR VALUE>"
    />
    

    Make sure , Don't use both ... if you need Location , Places and maps then use geo.API_KEY and if you need places and maps then use maps.v2.API_KEY

    0 讨论(0)
  • 2020-12-01 10:21

    Even if it's an already answered question this error can also appear if you call the super.onCreateViewin your fragment. It will crash at run time.

    Be sure you overridden the onCreateView method and inflated your layout:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.my_fragment, container, false);
        return view;
    }
    
    0 讨论(0)
  • 2020-12-01 10:22

    You are extending FragmentActivity, indicating that you are trying to use the Android Support package backport of fragments. However, your <fragment> element refers to MapFragment, which is for the native API Level 11 edition of fragments.

    Replace MapFragment with SupportMapFragment, and that should clear up this specific crash.

    0 讨论(0)
  • 2020-12-01 10:22

    Use the internet permission to be direct child of manifest file.. Like below and try..

    Also You should have the following for using map:

    1.Should extend Map activity in your activity file

    2.Should have API key i didn't see any key in your code.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.test_googlemap"
        android:versionCode="1"
        android:versionName="1.0" >
    
    
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-sdk
            android:minSdkVersion="3"
            android:targetSdkVersion="15" />
    
    0 讨论(0)
提交回复
热议问题