使用Google地图错误地扩展类片段

时间:2017-10-05 08:29:44

标签: android google-maps android-fragments

我在二进制XML上获取Error inflating class fragment,同时在活动中使用谷歌地图片段。我已经在这个论坛中搜索了许多类似的问题,但它仍然无法正常工作。我已将密钥放入我的Manifest文件中,但在应用程序标记中也会出现元数据错误。我正在记下我的两个代码:

activity.xml

 <RelativeLayout
                android:id="@+id/ll_Map"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            <fragment
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:clickable="true"
                />
    </RelativeLayout>

的Manifest.xml

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

</application>

Inside Activity.java

GoogleMap mMap = ((com.google.android.gms.maps.SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

错误日志:

Caused by: android.view.InflateException: Binary XML file line #379: Binary XML file line #379: Error inflating class fragment
                                                                                Caused by: android.view.InflateException: Binary XML file line #379: Error inflating class fragment
                                                                                Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 6587000 but found 10084000.  
You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

1 个答案:

答案 0 :(得分:1)

正如您的logcat所说:

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 6587000 but found 10084000.  

将google_play_services_version更改为6587000。