GoogleMapsDemo给IllegalStateException异常 [英] GoogleMapsDemo gives IllegalStateException

查看:134
本文介绍了GoogleMapsDemo给IllegalStateException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了所有步骤,这是在给谷歌,但最后它给的这个

 按errorCaused:java.lang.IllegalStateException:在应用的Andr​​oidManifest.xml中的元数据标签没有正确的价值。预计4132500但发现0您必须在&lt中的以下声明;用途>元素:其中,元数据机器人:名字=com.google.android.gms.version机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>

的Andr​​oidManifest.xml:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.googlemapsdemo
    安卓版code =1
    机器人:=的versionName1.0>    <许可
        机器人:名字=com.example.googlemapsdemo.permission.MAPS_RECEIVE
        安卓的ProtectionLevel =签名/>
    <使用许可权的android:NAME =com.example.googlemapsdemo.permission.MAPS_RECEIVE/>    <用途-SDK
        安卓的minSdkVersion =12
        机器人:targetSdkVersion =17/>    <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>    <! - 必须出示当前位置 - >
    <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>    <! - 所需的OpenGL ES 2.0。对于地图V2 - >
    <用途特征
        机器人:glEsVersion =0x00020000
        机器人:要求=真/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=com.example.googlemapsdemo.MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        &所述;元数据
            机器人:名字=com.google.android.maps.v2.API_KEY
            机器人:值=AIzaSyBLHwjdXsQK0sszxfrkoncHlqU3d2mDJok/>
    < /用途>< /清单>

MainActivity.java:

 包com.example.googlemapsdemo;进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.MapFragment;进口android.os.Bundle;
进口android.app.Activity;
进口android.view.Menu;
进口android.widget.Toast;公共类MainActivity扩展活动
{
    私人GoogleMap的GoogleMap的;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        尝试
        {
            //载入地图
            initilizeMap();        }赶上(例外五)
        {
            e.printStackTrace();
        }    }    / **
     *函数来加载地图。如果地图不创建它会为您创建它
     * * /
    私人无效initilizeMap()
    {
        如果(GoogleMap的== NULL)
        {
            GoogleMap的=((MapFragment)getFragmentManager()。findFragmentById(
                    R.id.map))的GetMap()。            //检查是否映射成功与否创建
            如果(GoogleMap的== NULL)
            {
                Toast.makeText(getApplicationContext(),
                        对不起!无法创建地图,Toast.LENGTH_SHORT)
                        。显示();
            }
        }
    }    @覆盖
    保护无效onResume()
    {
        super.onResume();
        initilizeMap();
    }
}


解决方案

清单文件

有关日食补充一点:

 <元数据机器人:名字=com.google.android.gms.version
 机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>

如果您使用的是Android的工作室(最新版本)与gradle0.7 +然后加入这一行:

 <元数据
        机器人:名字=com.google.android.maps.v2.API_KEY
        机器人:价值=你的钥匙/>

I have did all steps which is give at google but lastly it give's this

errorCaused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4132500 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" />

AndroidManifest.xml:

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

    <permission
        android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE" />

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

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

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <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.example.googlemapsdemo.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="AIzaSyBLHwjdXsQK0sszxfrkoncHlqU3d2mDJok" />
    </application>

</manifest>

MainActivity.java:

package com.example.googlemapsdemo;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity 
{
    private GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try 
        {
            // Loading map
            initilizeMap();

        } catch (Exception e) 
        {
            e.printStackTrace();
        }

    }

    /**
     * function to load map. If map is not created it will create it for you
     * */
    private void initilizeMap() 
    {
        if (googleMap == null) 
        {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

            // check if map is created successfully or not
            if (googleMap == null)
            {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

    @Override
    protected void onResume() 
    {
        super.onResume();
        initilizeMap();
    }
}

解决方案

manifest file

For eclipse add this :

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

If you are using Android Studio(latest version) with gradle0.7+ then add this line:

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Your Key" />

这篇关于GoogleMapsDemo给IllegalStateException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆