【问题标题】:How to resolve a "cannot inflate" runtime error in Android?如何解决 Android 中的“无法充气”运行时错误?
【发布时间】:2014-10-05 16:42:52
【问题描述】:

我的应用程序应该打开地图。我已经包含了播放服务,实现了片段并做了我能做的一切!但是,我在运行时遇到了“无法膨胀”的错误。

我将我的清单文件、布局文件和 logcat 错误。

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.xyz"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="21" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<permission
android:name="xyz.xyz.permission.MAPS_RECEIVE"
android:protectionLevel="signature"
/>
<uses-permission android:name="xyz.xyz.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="com.google.android.maps" />
    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
     <activity android:name="Home"
              android:label="@string/app_name">
        <intent-filter>

            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".HelloGoogleMaps" android:label="@string/app_name"
 android:theme="@android:style/Theme.NoTitleBar"/>
     <uses-library android:name="com.google.android.maps"/>
</application>

布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

tools:context="xyz.xyz.Home" >


        <fragment
            android:id="@+id/mapView"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/acceleration"
            android:layout_marginTop="20dp"
            android:apiKey="GoogleAPIKEY//I Added a Key, I just do not feel comfortable to display it"
            android:clickable="true"
            android:enabled="true" />

</RelativeLayout>

Logcat

01-05 04:33:18.003: E/AndroidRuntime(9303): FATAL EXCEPTION: main
01-05 04:33:18.003: E/AndroidRuntime(9303): java.lang.RuntimeException: Unable to start activity ComponentInfo{xyz.xyz/xyz.xyz.Home}: android.view.InflateException: Binary XML file line #20: Error inflating class fragment
01-05 04:33:18.003: E/AndroidRuntime(9303): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  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" />
01-05 04:33:18.003: E/AndroidRuntime(9303):     at com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
01-05 04:33:18.003: E/AndroidRuntime(9303):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)

还有更多,但这些看起来很重要。此外,它所说的添加为元数据的内容也已添加,但仍在生成异常。

【问题讨论】:

  • 在您的片段中,您有 android:layout_below="@+id/acceleration" 但没有 ID 为“acceleration”的组件
  • 我其实是把它作为一个textview..但是由于我的客户的版权问题,我不能在这里完全显示它..他坚持只显示重要信息。
  • 非常感谢您的建议和努力。

标签: android layout android-fragments fragment layout-inflater


【解决方案1】:

您的 Android SDK 中是否有 Google Play 服务 库?如果没有,请去检查http://developer.android.com/google/play-services/setup.html。 如果您想离线下载 Google Play 服务,请转至http://venomvendor.blogspot.com/2012/03/android-sdk-extras-by-google-inc.html

【讨论】:

  • 也做到了!该错误显示有关片段未膨胀的信息。我将感谢仅与此有关的答案。我还没有想出办法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-27
  • 2020-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-08
  • 2017-07-03
相关资源
最近更新 更多