您好我正在尝试将Google Maps Api用于我的应用程序而我只想显示地图,但我的logcat说明了这一点:
11-19 14:40:51.679: E/ActivityThread(18815): Failed to inflate
11-19 14:40:51.679: E/ActivityThread(18815): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
这是完整的logcat:http://wrttn.in/e7f3bc
这是我的activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
这是我的表现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<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" >
<activity
android:name="com.example.mapps.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="**key**"/>
</application>
我的MainActiviy.java没有任何额外的代码 如果有人知道问题出在哪里,我将不胜感激
答案 0 :(得分:0)
而不是:
android:name="com.google.android.gms.maps.MapFragment"
试试这个:
class="com.google.android.gms.maps.MapFragment"
请参阅:MapFragment Class Documentation
并检查您是否已将Google Play服务设置为项目中的库。你可以这样做:Setup Google Play Services in library
您可以阅读以下答案来帮助您:https://stackoverflow.com/a/16572141/2668136