在fragmentActivity中显示GoogleMaps v2的问题

时间:2015-02-11 20:00:29

标签: java android google-maps android-activity android-fragments

ERROR


02-11 14:34:17.613: E/AndroidRuntime(32281): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 14:34:17.613: E/AndroidRuntime(32281): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 6171000 but found 0.  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-11 14:38:57.243: E/AndroidRuntime(1234): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-11 14:38:57.243: E/AndroidRuntime(1234): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 6171000 but found 0.  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" />

MY MANIFEST


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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17"/>

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

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

        <meta-data 
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAVfrv4Xd-imNuljtdTolq2cw_qKrU-ME1"
            />

        <activity
            android:name=".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>
    </manifest>

注:


导入了google-play-services_lib库

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

和我的ActivityMain.java


package com.example.maps;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

1 个答案:

答案 0 :(得分:1)

您在错误消息中回答:

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

您必须在清单中添加:

<application>
    <meta-data 
       android:name="com.google.android.gms.version" 
       android:value="@integer/google_play_services_version" />
    ...
</application>

见以下链接:

http://developer.android.com/google/play-services/setup.html#Setup