GoogleMaps V2 java.lang.IllegalStateException

时间:2014-07-10 09:58:12

标签: android google-maps-android-api-2 android-maps-v2

我正在尝试实现一个简单的地图,它在lat上显示一个指针,我设置的时间很长。

但是在执行

时出现以下错误

PS:我已经按照获取地图密钥等所有步骤进行了操作。

07-10 15:13:36.175: E/AndroidRuntime(26185): FATAL EXCEPTION: main
07-10 15:13:36.175: E/AndroidRuntime(26185): Process: com.qcs.vivek.qcstrainingdemo, PID: 26185
07-10 15:13:36.175: E/AndroidRuntime(26185): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.qcs.vivek.qcstrainingdemo/com.qcs.vivek.qcstrainingdemo.MapDemo.MapDemo}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.ActivityThread.access$800(ActivityThread.java:139)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.os.Handler.dispatchMessage(Handler.java:102)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.os.Looper.loop(Looper.java:136)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.ActivityThread.main(ActivityThread.java:5102)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at java.lang.reflect.Method.invokeNative(Native Method)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at java.lang.reflect.Method.invoke(Method.java:515)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at dalvik.system.NativeStart.main(Native Method)
07-10 15:13:36.175: E/AndroidRuntime(26185): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.Activity.setContentView(Activity.java:1937)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.qcs.vivek.qcstrainingdemo.MapDemo.MapDemo.onCreate(MapDemo.java:23)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.Activity.performCreate(Activity.java:5248)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
07-10 15:13:36.175: E/AndroidRuntime(26185):    ... 11 more
07-10 15:13:36.175: E/AndroidRuntime(26185): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 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" />
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.maps.internal.q.v(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.maps.internal.q.u(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.dynamic.a.a(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.app.Activity.onCreateView(Activity.java:4802)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
07-10 15:13:36.175: E/AndroidRuntime(26185):    ... 21 more

我的清单文件

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

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

    <uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" />

    <permission
        android:name="com.example.googlemaps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.qcs.vivek.qcstrainingdemo.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>


         <activity
            android:name="com.qcs.vivek.qcstrainingdemo.MapDemo.MapDemo"
            android:label="@string/app_name" >
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>


        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDfMZF88sAuTl5bzIDUp-dpiGz6EbWasW0" />
    </application>

</manifest>

1 个答案:

答案 0 :(得分:2)

正如你的logcat清楚地说的那样

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 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" />
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
07-10 15:13:36.175: E/AndroidRuntime(26185):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)

您需要在<meta-data>

<application>标记下添加Google Play服务版本manifest.xml标记
 <meta-data
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />