【问题标题】:Error inflating class fragment using Google Maps使用谷歌地图膨胀类片段时出错
【发布时间】:2017-10-05 08:29:43
【问题描述】:

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

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>

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" />

【问题讨论】:

  • 您必须在清单中声明 google_maps_key
  • @ysl 感谢您的回复。我做了那个改变,但我仍然收到这个错误。请帮我解决它。
  • 你需要为此生成密钥
  • @ysl,我已经在此处进行了更改并从 Google 控制台启用了密钥。但错误是一样的

标签: android google-maps android-fragments


【解决方案1】:

正如你的日志猫所说:

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。

【讨论】:

  • 非常感谢。有用。我为它编辑了那个值文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-26
  • 1970-01-01
  • 2012-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多