我正在尝试添加google map v2,这里是主要的布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.test.map.CustomAutoCompleteTextView
android:id="@+id/atv_places"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="@string/str_atv_places"
android:singleLine="true" />
<fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@id/atv_places" />
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<permission
android:name="com.test.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.test.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.test.map.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>
</application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="mykey" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
我已导入播放服务库项目及其在工作区中的副本
上述步骤取自谷歌提供的文件。现在,一切似乎都很完美,我得到以下例外:
02-09 11:39:30.227: E/AndroidRuntime(5153): FATAL EXCEPTION: main
02-09 11:39:30.227: E/AndroidRuntime(5153): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.map/com.test.map.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.os.Looper.loop(Looper.java:137)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.main(ActivityThread.java:5103)
02-09 11:39:30.227: E/AndroidRuntime(5153): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 11:39:30.227: E/AndroidRuntime(5153): at java.lang.reflect.Method.invoke(Method.java:525)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-09 11:39:30.227: E/AndroidRuntime(5153): at dalvik.system.NativeStart.main(Native Method)
02-09 11:39:30.227: E/AndroidRuntime(5153): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.Activity.setContentView(Activity.java:1895)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.test.map.MainActivity.onCreate(MainActivity.java:53)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.Activity.performCreate(Activity.java:5133)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
02-09 11:39:30.227: E/AndroidRuntime(5153): ... 11 more
02-09 11:39:30.227: E/AndroidRuntime(5153): 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" />
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.internal.q.v(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.internal.q.u(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.SupportMapFragment$b.eb(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.dynamic.a.a(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
02-09 11:39:30.227: E/AndroidRuntime(5153): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-09 11:39:30.227: E/AndroidRuntime(5153): ... 21 more
Logcat说缺少以下标记,但我的清单中有它。
02-09 11:39:30.227: E/AndroidRuntime(5153): 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" />
为什么我会遇到这个问题,尽管一切都已到位?任何帮助表示赞赏。
答案 0 :(得分:2)
您可以在布局文件中使用FrameLayout
代替Fragment
吗?然后在代码中创建一个supportmapfragment实例,并用此片段替换FrameLayout
。它将解决您的问题。
答案 1 :(得分:1)
不要忘记查看大小写。
02-09 11:39:30.227:E / AndroidRuntime(5153):引起:android.view.InflateException:二进制XML文件行#15:错误膨胀类片段
您似乎忘记了对Fragment类名称进行操作。
<Fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@id/atv_places" />
答案 2 :(得分:1)
元数据标记必须是应用程序标记的子标记:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="mykey" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity ....